C
C#10mo ago
Naarfy

Converting the Sqlite template to Postgresql

Hello, I started a new project with the template
dotnet new blazor --auth Individual --interactivity Auto
dotnet new blazor --auth Individual --interactivity Auto
It comes with a Sqlite Db. I want to change it to Postgres. I installed the packages and change UseSqlite to UseNpgsql. It connects to my db and the initial migration works, it creates the tables on my db. The issue i'm having is if I try to create a user for example, I get :
PostgresException: 42804: column "EmailConfirmed" is of type integer but expression is of type boolean POSITION: 303
PostgresException: 42804: column "EmailConfirmed" is of type integer but expression is of type boolean POSITION: 303
I guess there is some casting going on and Postgres doesn't want to use a boolean as an integer. If I look into
ApplicationDbContextModelSnapshot.cs
ApplicationDbContextModelSnapshot.cs
I see :
b.Property<bool>("EmailConfirmed").HasColumnType("INTEGER");
b.Property<bool>("EmailConfirmed").HasColumnType("INTEGER");
The issue I have is that this file is auto generated. If I search the field EmailConfirmed that's pretty much all I have. The variable declaration and this. At that point can I tell EF to make sure the colu;mn stays a bool ?
6 Replies
Pobiega
Pobiega10mo ago
You will need to recreate your migrations if you swap provider They contain dB specific stuff, as you noticed
Naarfy
NaarfyOP10mo ago
Delete all migrations, drop tables and recreate migrations ?
Pobiega
Pobiega10mo ago
Yup
Naarfy
NaarfyOP10mo ago
Alright, thanks a lot !
Pobiega
Pobiega10mo ago
Delete the snapshot too
Naarfy
NaarfyOP10mo ago
That makes a lot of sense actually, I need to get better at databases, thanks for your help
Want results from more Discord servers?
Add your server