-
Notifications
You must be signed in to change notification settings - Fork 256
Description
I am working with the latest .NET. using Visual Studio 2026.

In my application, I would like to support several database provider, including PostgreSQL.
But, it cannot create database when I call context.DatabaseMigrate() in the source for postgreSQL, which works for all other database provider(I tested it with LocalDB, SQLServer, SQLite). Then I changed the server name from localhost to 127.0.0.1 as suggested, nothing changed.

Next, I manually called Update-Database after Add-Migration operation in Package Manager Console, it works, the database really created. And all tables, including __EFMigrationsHistory, are created there.

there is an error line in the picture but the database really created.
Next I put code to set default schema to public.

then call Update-Database again(I have dropped the database created on last step), this time it failed.

Ok, let's continue with last database created step.
After database created with Update-Database, I run my application, when it goes to context.Database.Migrate(), it show me

I know 100% that there is no pending migration.(I called Update-Database, and there is only one migration existing and it must have been applied when Update-Database is called).
To verify,

the pendingMigrations really has nothing.
I can jump context.Database.Migrate() to avoid the error message popup in the way shown in above picture.
Then I made another try,
- I create an empty database with pgAdmin (like customer do)

- I run the application, and the application will call context.Database.Migrate()

- I checked the Tables, nothing inside

NOTE:
context.Database.EnsureCreated() can always create database.
The problem for me is that, context.Database.Migrate() call doesn't really create the database. But I need to create database in this way.
