Reputation: 9480
Very quick question.
I work on a MVC 5 Code First project and I do a lot of small changes in the DB models. Sometimes the changes overwrite previous ones.
Is it safe to update-database -targermigration InitialCreate
and then remove all migrations (except initial) and add-migration cumulative
?
I expect expert opinions like Yes or No.
Thank you in advance.
Upvotes: 0
Views: 632
Reputation: 17506
It'd be interesting to know other people's practices on this, but I'll add what I would do. (Disclaimer: I haven't done this myself in a long time)
A bit of context first. Code migrations are snippets of code telling the database how to update itself after you make a change in your model classes. Since you're doing development and you haven't pushed code to production, there's no point in doing migrations because there is no production database that needs taking care of. For now, if needed, you could simply delete your local DB and rebuild it from scratch every time you make a change. But this is time consuming.
But there is a better way: automatic migrations. Every time you make a change and call Update-Database
, EF will (behind the scenes) create a migration and update the database for you.
Enable-Migrations –EnableAutomaticMigrations
.Update-Database
.Note that in some changes will still require that you add a migration manually, as specified here.
Now, this is obviously not suited for a production environment, for a variety of reasons.
So when you're done building the MVP version of your app, I would just delete the local DB, and override the initial migration as shown here.
InitialCreate.cs
(or the entire Migrations
folder for that matter...)Add-Migration InitialCreate
Update-Database -Force
.Upvotes: 1