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

  1. Remove all files in Migrations folder of shipfastblazor root folder
  2. Open command line and change to shipfastblazor folder
  3. Install database driver, for this example: dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL --version 8.0.2
  4. 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;"
     },
    
  5. Update Program.cs file to change from SQLite to PostgreSQL like this
    builder.Services.AddDbContext<ApplicationDbContext>(options =>
    options.UseNpgsql(connectionString));
    
  6. Create migration with this command: dotnet ef migrations add Init
  7. Update databse: dotnet ef database update
  8. Run the app
An unhandled error has occurred. Reload 🗙