Issue
I am experimenting with EF Core 6 on a linux box to see if I can use code first approach to build a complex set of objects on a PostgreSQL database
When I tried the same with sqlite db context, it was successful from first attempt, but once I switch to postgresql things are not working as expected
I tried both migrating sqlite experiment, and starting from scratch and both gave me this error message
Build started...
Build succeeded.
Unable to create an object of type 'LedgerDataContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
I did add connection string to my DI in a web api project referencing my data project
am I missing something?
Solution
Here is a workaround;
- switch your data context to sqlite
- generate a migration and update your local database
dotnet ef migrations add sqlite_migration
dotnet ef database update
- switch back to postgresql context
- on your postgres database, create a table "__EFMigrationsHistory" with two text fields
- "MigrationId"
- "ProductVersion"
CREATE TABLE "__EFMigrationsHistory" (
"MigrationId" text,
"ProductVersion" text
)
- Delete your Migrations folder from your code as if you are starting from an initial migration
- Now you are ready to migrate your context to PG DB from linux EF Core 6
dotnet ef migrations add first_pg_migration
dotnet ef database update
ps: this question seems similar but for mysql -> EF Core - Table '*.__EFMigrationsHistory' doesn't exist
Answered By - A.Rashad Answer Checked By - Willingham (WPSolving Volunteer)