Why I can't get Entity Framework Migration to

2019-04-02 01:49发布

问题:

I have deleted development database, and Migrations folder from project. When running unit test with use my project development database is recreated. I don't understand why running update-database gives me

PM> Update-Database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Applying code-based migrations: [201302201840012_wieleDoWielu].
Applying code-based migration: 201302201840012_wieleDoWielu.

Why migration: 201302201840012_wieleDoWielu is remembered ? How Can I delete it? Where is stored?

Best Regards Przemysław Staniszewski

回答1:

Here's a answer. Please recover migration folder and its migrations file (recover to your project). Then follow steps from my theard http://pawel.sawicz.eu/entity-framework-reseting-migrations/

1) Update-Database -Targetmigration:0 - it's the key! first
2) Wipe out tables/migrations (you dont have to delete whole folder)
3) Add-Migration Initialise
4) Update-Database



回答2:

Try these commands Sqllocaldb.exe stop V11.0 Sqllocaldb.exe delete V11.0

This should remove the reference. You may have to comment out some of the changes before doing this and then re-instating the changes back into model before doing the migration.

I'm new at this, so hopefully I am understanding your problem, because it sounds like the same one I encountered recently.

A more permanent solution may be to add the following code to your Globel file and replace the with what you need it to be. The article for this can be found at the link below also:

Database.SetInitializer(new DropCreateDatabaseIfModelChanges<PersonContext>()); 

http://ilmatte.wordpress.com/2012/12/05/entity-framework-5-code-first-enabling-migrations-in-a-real-project/