-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Migrations are too aggressive on RenameColumn #15178
Comments
@yepeekai It's not possible to know for sure when something is a rename, so sometimes the heuristics will detect dropping and adding as a rename when it isn't. We discussed this in triage and didn't come up with anything specific we can do better, but if you have any suggestions from your specific case we would be interested in hearing them. |
I think the example I gave would qualify as a suggestion on a case that should not be a rename... If it is a foreign key and it is for a different table then it is not a rename... |
@yepeekai Thanks--we will discuss. |
Maybe add an "OldColumnName" attribute to tell EFCore that a rename is useful when a migration is created...? |
Maybe add an option to add-migration, e.g. -no-renames? |
Suggestion: public partial class MyRenameCustomMigration : CustomMigration
{
protected override void Up(CustomMigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "FullName",
schema: "sample",
table: "Customers",
newName: "FirstName");
migrationBuilder.DoNotRename(
name: "EntityAId",
schema: "sample",
table: "Customer");
}
Ef migrations will generate other changes as usual but not touch the column names touched by the CustomMigration and then merge all changes into the migration file i.e Future IDE tooling can also opt to include helpers to generate |
I have another idea:
This design identity could also be written to the column in the database by using extended properties on the column for example. |
|
Consider also not renaming if multiple properties are equal candidates for the rename. See #29902. |
We made huge refactoring of our model for a new application. There is a lot of RenameColumn in the generated Migration and a lot of them don't make sense: Foreign keys have been removed and added to different tables and EF Core choose to rename columns even when the foreign key is for a different table.
If we drop EntityAId (pointing to EntityA) and add EntityBId (pointing to EntityB), it shouldn't be a rename but a drop and add.
I think it should be a DropColumn and a AddColumn instead of a RenameColumn for a foreign key that points to different entities.
The text was updated successfully, but these errors were encountered: