Reputation: 5856
There's a lot of articles on this topic and I've spent hours reading them today. It's so confusing - most of the articles seem to try to save existing databases and even migration history.
My databases were created initially by code first migrations. I really don't have any data that's important to keep. So I would like to just delete my databases and the .cs migration history files in /Migrations folder. Then run add migrations
and update-database
to recreate the databases.
From what I'm reading, this is not the way to do it? My confusion is partially due to the totally different procedures suggested and the extensive coding for many solutions.
Can I delete my databases and /Migrations/*.*
(except for Configurations.cs) and essentially reinitialize Migrations?
Btw, I am using VS Web Express 2013, MVC5/C#, SQL Express 2012.
Upvotes: 0
Views: 105
Reputation: 12248
I regularly do this during the development phase of my projects, as long as you are happy to lose your data then it is fine to delete the database, and migration classes, the database will be recreated when you run update-database
.
During early development phases, my approach is to utilise automatic migrations and just use update-database
which means nothing is created in the migrations folder, so you don't have to manage the extra files.
Obviously this approach isn't good once you start deploying the database for real, where I personally wouldn't use automatic migrations.
To enable automatic migrations, run the Enable-Migrations –EnableAutomaticMigrations
command in the Package Manager Console.
More reading:
http://msdn.microsoft.com/en-us/data/dn481501.aspx
http://msdn.microsoft.com/en-gb/data/jj554735.aspx
Upvotes: 1