简体   繁体   中英

Entity Framework Code First Migrations Error on published Asp.net MVC IIS

I have created an asp.net mvc Project that is using the Entity Framework Code first. Migrations are enabled. When I deploy Project on IIS , the migrations error that occurs is:

Migrations is enabled for context 'MyContext' but the database does not exist or contains no mapped tables. Use Migrations to create the database and its tables, for example by running the 'Update-Database' command from the Package Manager Console.**

Try using this putting in your global.asax

Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyContext, Configuration>());
        using (MyContext temp = new MyContext())
        {
            temp.Database.Initialize(true);
        }

I had the same problem recently, I solved it like this:

  1. In the constructor of your Configuration class turn off the migration:

public Configuration() { AutomaticMigrationsEnabled = false; }

  1. Drop the table __MigrationHistory from your production database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM