You want to make changes to your Models and Database, you have auto migration enabled and you run:
update-database -force
you get this error:
'FK_dbo.{TABLENAME}_dbo.{OTHER_TABLENAME}_otherID' is not a constraint.
Could not drop constraint. See previous errors.
You sh*t a brick.
Solution:
Run this:
Add-Migration Update{You Model Name}Class
This creates a file in Migrations containing a Partial Class outlining what changes the Framework is attempting as a "best guess"
Remove any unwanted changes in this file.
E.g DropForeignKey("dbo.{TABLENAME}", "otherID", "dbo.{OTHER TABLE}");
Now run:
Update-Database –TargetMigration:Update{You Model Name}Class
NOW READ THIS, TWICE!
http://msdn.microsoft.com/en-gb/data/jj591621.aspx#customizingAnd if none of that works
If you're still getting errors, and trust me, it happens. Then I recommend backing everything up and starting with a clean slate.
I followed the instructions here http://stackoverflow.com/questions/11679385/reset-entity-framework-migrations from Todd. Thank's Todd :)
- Delete the migrations folder in your project
- Delete the __MigrationHistory table in your database (may be under system tables)
- In PM Console run: Enable-Migrations -EnableAutomaticMigrations -Force
- In PM Console run: Add-Migration Initial
- In PM Console run: update-databse -TargetMigration:Initial
No comments:
Post a Comment