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:
public Configuration() { AutomaticMigrationsEnabled = false; }
__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.