Alex Rivera | Logout

EF Migrations: RenameColumn in Automatic Migrations?

Asked 2012-09-10T16:30:58.203
18

If you rename a property, the Visual Studio IDE is smart enough to help you refactor to rename that property throughout your code. If that rename is on a model used in EF Migrations, and you run a standard automatic migration like:

update-database -f

You'll get this:

AddColumn("NewName"...
DropColumn("OldName"...

Not what you wanted. Obviously running Add-Migration at this point will let you go in and manually change these 2 calls to a single call to RenameColumn, but is there some way to get Automatic Migrations to do this automatically? Some approach to property rename that I'm not doing right, perhaps?

I'm using EF 5.0 in VS2012, but this behavior appears in EF 4.3.1 and VS2010 as well.

Edit
Report

1 Answer

5

My opinion: EF has no idea that that you have renamed existing column. Refactoring is design time change without any persisted information about the change so when you run migrations, EF simply don't know how to differ between renaming and real deletion/adding of a new column.

answered 2012-09-10T19:37:43.647

Your Answer