I've been using EF 5 Code First, successfully, in my app. I have roughly 40 tables. However, I've run into an issue that I can seem to get Migrations to handle correctly. So, what I would like to do is to somehow tell EF to treat the current schema of the database as a new starting point, and start managing it from this point. This way, I can make the necessary schema change manually, and then tell EF to essentially start over from this point.
Is there a way I can do this? I presume I'm going to have to delete the __MigrationHistory table, or remove its contents. But I'm not sure how best to proceed with doing this.
You should be able to do the following:
Change your database manually to reflect the changes in the model that wont be handled by a migration. Everything should work now, but the database and the migration system are out of sync.
Run Add-Migration ManuallyUpdatedDatabase -IgnoreChanges
. This creates a migration that is completely empty, so it wont make any changes to the database, but it will make sure that the system knows about the manual changes that have been made. That way the manual changes wont be included in the next migration you create.
Run Update-Database
to apply the empty migration.
From here on everything should work as usual. You just have a "missing link" in your migrations because you have handled some changes manually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With