Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing column collation requires indexes to be rebuilt #21547

Closed
ajcvickers opened this issue Jul 7, 2020 · 0 comments
Closed

Changing column collation requires indexes to be rebuilt #21547

ajcvickers opened this issue Jul 7, 2020 · 0 comments
Assignees
Labels
area-migrations closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@ajcvickers
Copy link
Member

Applying migration '20200707160136_Collation'.
Failed executing DbCommand (12ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
DECLARE @var0 sysname;
SELECT @var0 = [d].[name]
FROM [sys].[default_constraints] [d]
INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
WHERE ([d].[parent_object_id] = OBJECT_ID(N'[Passwords]') AND [c].[name] = N'Text');
IF @var0 IS NOT NULL EXEC(N'ALTER TABLE [Passwords] DROP CONSTRAINT [' + @var0 + '];');
ALTER TABLE [Passwords] ALTER COLUMN [Text] nvarchar(450) COLLATE SQL_Latin1_General_CP1_CS_AS NULL;
Microsoft.Data.SqlClient.SqlException (0x80131904): The index 'IX_Passwords_Text' is dependent on column 'Text'.
ALTER TABLE ALTER COLUMN Text failed because one or more objects access this column.
   at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at Microsoft.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean isAsync, Int32 timeout, Boolean asyncWrite)
   at Microsoft.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String methodName)
   at Microsoft.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
   at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCommands, IRelationalConnection connection)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String connectionString, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
ClientConnectionId:0b1845a0-1689-4417-947c-4d4dd7a333ec
Error Number:5074,State:1,Class:16
The index 'IX_Passwords_Text' is dependent on column 'Text'.
ALTER TABLE ALTER COLUMN Text failed because one or more objects access this column.

Workaround is to manually add in the migration the drop/create for the index.

@ajcvickers ajcvickers added this to the 5.0.0 milestone Jul 10, 2020
@ajcvickers ajcvickers removed this from the 5.0.0 milestone Jul 20, 2020
bricelam added a commit to bricelam/efcore that referenced this issue Jul 23, 2020
Changes:
- Synthesize DEFAULT value when column altered to NOT NULL (fixes dotnet#19882)
- SQL Server: Rebuild indexes when column collation is altered (fixes dotnet#21547)
bricelam added a commit to bricelam/efcore that referenced this issue Jul 23, 2020
Changes:
- Synthesize DEFAULT value when column altered to NOT NULL (fixes dotnet#19882)
- SQL Server: Rebuild indexes when column collation is altered (fixes dotnet#21547)
@bricelam bricelam added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jul 23, 2020
@bricelam bricelam added this to the 5.0.0-preview8 milestone Jul 23, 2020
bricelam added a commit to bricelam/efcore that referenced this issue Jul 24, 2020
Changes:
- Synthesize DEFAULT value when column altered to NOT NULL (fixes dotnet#19882)
- SQL Server: Rebuild indexes when column collation is altered (fixes dotnet#21547)
bricelam added a commit to bricelam/efcore that referenced this issue Jul 24, 2020
Changes:
- Synthesize DEFAULT value when column altered to NOT NULL (fixes dotnet#19882)
- SQL Server: Rebuild indexes when column collation is altered (fixes dotnet#21547)
@ajcvickers ajcvickers modified the milestones: 5.0.0-preview8, 5.0.0 Nov 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-migrations closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

2 participants