You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create new db with default schema 'public'. Then apply some EF migrations. Table __EFMIgrationsHistory must be created
Customize search_path in the db ALTER ROLE ALL SET search_path TO 'custom'
Do not specify search path in connection string.
3, Create new migration and apply it
There is such exception.
Unhandled exception. Npgsql.PostgresException (0x80004005): 42P07: relation "__EFMigrationsHistory" already exists
at Npgsql.Internal.NpgsqlConnector.ReadMessageLong(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteNonQuery(Boolean async, CancellationToken cancellationToken)
at [Microsoft.EntityFrameworkCore.Storage](http://microsoft.entityframeworkcore.storage/).RelationalCommand.ExecuteNonQueryAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at [Microsoft.EntityFrameworkCore.Storage](http://microsoft.entityframeworkcore.storage/).RelationalCommand.ExecuteNonQueryAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at [Microsoft.EntityFrameworkCore.Storage](http://microsoft.entityframeworkcore.storage/).RelationalCommand.ExecuteNonQueryAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.MigrateAsync(String targetMigration, CancellationToken cancellationToken)
at Npgsql.EntityFrameworkCore.PostgreSQL.Migrations.Internal.NpgsqlMigrator.MigrateAsync(String targetMigration, CancellationToken cancellationToken)
It's because repository falls back in schema 'public':
In my project I've by-passed this behavior by searching with schema only when TableSchema is specified, there is no fallback in public. If schema is not specified, searchin is performed only with table name
The text was updated successfully, but these errors were encountered:
I hit exactly this issue last week. It's inconsistent behaviour because if you use the command-line tooling to generate the corresponding SQL script (ef migrations script), there's no mention of the explicit public schema.
Btw, the workaround I ended up putting in was to add a DbCommandInterceptor which intercepts the above SQL running and removes public and replaces it with a schema of my choice.
Step:
__EFMIgrationsHistory
must be createdALTER ROLE ALL SET search_path TO 'custom'
Do not specify search path in connection string.
3, Create new migration and apply it
There is such exception.
It's because repository falls back in schema 'public':
efcore.pg/src/EFCore.PG/Migrations/Internal/NpgsqlHistoryRepository.cs
Lines 28 to 44 in 18d07c5
In my project I've by-passed this behavior by searching with schema only when TableSchema is specified, there is no fallback in public. If schema is not specified, searchin is performed only with table name
The text was updated successfully, but these errors were encountered: