frankcollins3 / ASPokedex

Pokedex with ASP backend / razor pages, and VanillaJS front end
1 stars 0 forks source link

👎 entity framework database migrations [7:27am] #14

Closed frankcollins3 closed 12 months ago

frankcollins3 commented 12 months ago

attempting to do: dotnet ef database update

error: Screen Shot 2023-09-20 at 7 26 21 AM

proposed approach: read docs and have an outside opinion from chatGPT

possible improvements:

frankcollins3 commented 12 months ago

entity framework tools isn't downloaded yet. kind of confused because I used: dotnet new package ef && the postgres package without fail but this is clearly different.

➜ aspokedex git:(master) ✗ dotnet tool install --global dotnet-ef

Tools directory '/Users/me/.dotnet/tools' is not currently on the PATH environment variable. If you are using zsh, you can add it to your profile by running the following command:

cat << \EOF >> ~/.zprofile

Add .NET Core SDK tools

export PATH="$PATH:/Users/me/.dotnet/tools" EOF

And run zsh -l to make it available for current session.

You can only add it to the current session by running the following command:

export PATH="$PATH:/Users/me/.dotnet/tools"

You can invoke the tool using the following command: dotnet-ef Tool 'dotnet-ef' (version '7.0.11') was successfully installed. ➜ aspokedex git:(master) ✗

[7:30am]

frankcollins3 commented 12 months ago

1: cat << \EOF >> ~/.zprofile 2: dotnet ef database update

👍 3: Screen Shot 2023-09-20 at 7 32 36 AM

👎 4: Screen Shot 2023-09-20 at 7 33 29 AM [7:33am]

slight confusion at the return of: Your startup project 'aspokedex' doesn't reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.

using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using Npgsql.EntityFrameworkCore.PostgreSQL; // For PostgreSQL support
using Pokemon.Models; // Your DbContext and models namespace

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorPages();

// Configure the DbContext and connection string
builder.Services.AddDbContext<ApplicationDbContext>(options =>
    options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));

builder.Services.AddHttpClient("PokeApi", client =>
{
    client.BaseAddress = new Uri("https://pokeapi.co/api/v2/");
    // Configure other HttpClient options if needed
});
// var httpClient = _httpClientFactory.CreateClient("PokeApi");         // this is then used through the rest of the app.

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.MapRazorPages();

app.Run();

[7:42am]

frankcollins3 commented 12 months ago

Screen Shot 2023-09-20 at 7 44 17 AM [7:48am]

dotnet add package Microsoft.EntityFrameworkCore.Design [7:51am]

frankcollins3 commented 12 months ago

👍 Screen Shot 2023-09-20 at 7 52 29 AM Screen Shot 2023-09-20 at 7 53 11 AM Screen Shot 2023-09-20 at 7 53 09 AM [7:53am]

frankcollins3 commented 12 months ago

// sidenote on wondering if there is likeness to: npx prisma migrate dev (if prisma models don't link correctly to the psql/db tables it doesn't migrate) [7:55am]

frankcollins3 commented 12 months ago

can't tell if it's something besides the migrations but leaving cloesd for now. 1 final command below to check: Screen Shot 2023-09-20 at 8 12 28 AM [8:12am]