Unfortunately, the solution provided for #3713 does not work for us.
I also tried "modelBuilder.HasPostgresExtension("public");"
The error I get is "42501: Because postgis isn't a trusted extension, only members of "azure_pg_admin" are allowed to use CREATE EXTENSION postgis".
I included my original comment below.
Scripting migrations is cumbersome and error prone, please assist in finding a solution that works in our setup.
Hi,
We are on EFCore / Npgsql / Net10, and we have the same issue on Azure Postgres. The following command is always added to the modelsnapshot, regardless if I add a check or not (using modelBuilder.HasPostgresExtension):
NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "postgis");
On Azure, the superuser has the permissions to install extensions in schema public. However, we run migrations under a different user (and in different schemas), so we cannot use the superuser account. I found that on Azure, the following SQL runs without errors under the "migrations" user (in January 2026):
CREATE EXTENSION IF NOT EXISTS postgis with schema public;
Please note: this statement now (April 2026) also gives the error mentioned above, so my original suggestion would no longer help...
However, this SQL is never generated, even when I provide
modelBuilder.HasPostgresExtension("public", "postgis");
Is there a workaround (other than script the migration and apply that script manually)? Or would it be possible to fix the generated code for the HasPostgresExtension method...
Originally posted by @rhuesken in #3496
Unfortunately, the solution provided for #3713 does not work for us.
I also tried "modelBuilder.HasPostgresExtension("public");"
The error I get is "42501: Because postgis isn't a trusted extension, only members of "azure_pg_admin" are allowed to use CREATE EXTENSION postgis".
I included my original comment below.
Scripting migrations is cumbersome and error prone, please assist in finding a solution that works in our setup.
Please note: this statement now (April 2026) also gives the error mentioned above, so my original suggestion would no longer help...
Originally posted by @rhuesken in #3496