Skip to content

Repository files navigation

Database Initialization for the project

Creating the database locally Using Docker

docker run -d \
  --name postgres-movie \
  -p 5432:5432 \
  -e POSTGRES_DB=movie \
  -e POSTGRES_USER=postgres \
  -e POSTGRES_HOST_AUTH_METHOD=trust \
  -v pgdata_movie:/var/lib/postgresql/data \
  -v ./init.sql:/docker-entrypoint-initdb.d/init.sql \
  postgres:16

Generating the DB Context

dotnet ef dbcontext scaffold "Host=localhost;Port=5432;Database=movie;Username=postgres;Password=" \
  Npgsql.EntityFrameworkCore.PostgreSQL \
  --output-dir Models/EntityFramework \
  --context-dir Models \
  --context AppDbContext \
  --no-onconfiguring \
  --force

Adding the DB Context to the project

builder.Services.AddDbContext<AppDbContext>(options =>
    options.UseNpgsql("Host=localhost;Port=5432;Database=movie;Username=postgres;Password=")
);

Creating and applying migration

dotnet ef migrations add InitialMigration
dotnet ef database update

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages