Skip to content

Commit 3f8eb8c

Browse files
authored
Remove legacy rename column operation hack and replace it with exception. (PomeloFoundation#1665)
1 parent 1450c7e commit 3f8eb8c

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

src/EFCore.MySql/Migrations/MySqlMigrationsSqlGenerator.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -830,23 +830,11 @@ protected override void Generate(
830830
.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name))
831831
.Append(" ");
832832

833-
var column = model?.GetRelationalModel().FindTable(operation.Table, operation.Schema).FindColumn(operation.NewName);
834-
if (column == null)
833+
var column = model?.GetRelationalModel().FindTable(operation.Table, operation.Schema)?.FindColumn(operation.NewName);
834+
if (column is null)
835835
{
836-
if (!(operation[RelationalAnnotationNames.ColumnType] is string type))
837-
{
838-
throw new InvalidOperationException(
839-
$"Could not find the column: {Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Table, operation.Schema)}.{Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.NewName)}. Specify the column type explicitly on 'RenameColumn' using the \"{RelationalAnnotationNames.ColumnType}\" annotation");
840-
}
841-
842-
builder
843-
.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.NewName))
844-
.Append(" ")
845-
.Append(type)
846-
.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator);
847-
848-
EndStatement(builder);
849-
return;
836+
throw new InvalidOperationException(
837+
$"The column '{Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Table, operation.Schema)}.{Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.NewName)}' could not be found in the target model. Make sure the table name exists in the target model and check the order of all migration operations. Generally, rename tables first, then columns.");
850838
}
851839

852840
var columnType = (string)(operation[RelationalAnnotationNames.ColumnType] ??

0 commit comments

Comments
 (0)