-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
MigrationBuilder.RenameIndex(...) has an optional parameter "table". When this parameter is not provided rename/migration fails
Steps to reproduce
add this to any migration
migrationBuilder.RenameIndex("existingIndex", "newIndexName");
The issue
The migration is executed and fails with
Exception message: System.Data.SqlClient.SqlException (0x80131904): Either the parameter @objname is ambiguous or the claimed @objtype (INDEX) is wrong.
Stack:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, String executeMethod, IReadOnlyDictionary`2 parameterValues, Boolean openConnection, Boolean closeConnection)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues,Boolean manageConnection)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommandExtensions.ExecuteNonQuery(IEnumerable`1 commands, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Execute(IEnumerable`1 relationalCommands)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Tools.Cli.DatabaseUpdateCommand.<>c__DisplayClass0_0.<Configure>b__0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
Further technical details
The generated SQL looks like this:
EXEC sp_rename N'.existingIndex', N'newIndexName', N'INDEX';
- note the dot in first parameter
Rename SQL is generated here: https://github.com/aspnet/EntityFramework/blob/d5f39e3532c352c227a80ca40237a9121f17dc6e/src/Microsoft.EntityFrameworkCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs#L113
RenameIndex method should have non-optional table parameter or there should be a check for non-empty string in the linked method to provide better logging.
EF Core version: 1.0.0-rc2-final
EF Core tools version: 1.0.0-preview1-final
Operating system: Win X
DB: SQL 12.0.2000
Visual Studio version: dotnet-cli