How to change database
Default database is SQLite for ease of use and easy to deploy. However, it's not for everyone. Because of Entity Framework Core, you can change it to different database, here is what I would do to change to PosgreSQL/CockroachDB
- Remove all files in
Migrations
folder ofshipfastblazor
root folder - Open command line and change to
shipfastblazor
folder - Install database driver, for this example:
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL --version 8.0.2
- Update connection string in
appsettings.json
to"ConnectionStrings": { "DefaultConnection": "host=localhost;port=26257;database=mydatabase;user id=mydbuser;password=mypassword;Trust Server Certificate=True;Pooling=True;Minimum Pool Size=2;" },
- Update
Program.cs
file to change from SQLite to PostgreSQL like thisbuilder.Services.AddDbContext<ApplicationDbContext>(options => options.UseNpgsql(connectionString));
- Create migration with this command:
dotnet ef migrations add Init
- Update databse:
dotnet ef database update
- Run the app