EF 5. "Automatic migration was not applied because it would result in data loss" - only changed the column name

TheMook picture TheMook · Aug 1, 2013 · Viewed 34.5k times · Source

I have:

AutomaticMigrationsEnabled = True
AutomaticMigrationDataLossAllowed = False

in my configuration file and the existing model is:

Public Property ID() As Integer
Public Property ERP_ArticleCode() As String
Public Property description() As String

All I did was change the 3rd column from "description" to "am_description" and ran "update-database -verbose" which resulted in "Automatic migration was not applied because it would result in data loss"!

I do not understand this... why can't I just change a column name and update the database - this shouldn't be a dataloss issue, should it? Am I doing something wrong?

Answer

This code below isn't necessary to run your Migration:

AutomaticMigrationsEnabled = True
AutomaticMigrationDataLossAllowed = False

And, acording to this article (from entityframework codeplex), this is an EF error and you can ignore this with -Force attribute in your migration.

Update-Database -Force

or

Update-Database -TargetMigration: X -Force

It should resolve your problem.

IMO, you should let EF decide what does with your columns, just my opinion.