[英]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. 我创建了一个asp.net
mvc
项目,该项目首先使用实体框架代码。 Migrations are enabled. 启用了迁移。 When I deploy Project on IIS
, the migrations error that occurs is: 当我在IIS
上部署Project时,发生的迁移错误是:
Migrations is enabled for context 'MyContext' but the database does not exist or contains no mapped tables. 已为上下文“ MyContext”启用了迁移,但是数据库不存在或不包含映射表。 Use Migrations to create the database and its tables, for example by running the 'Update-Database' command from the Package Manager Console.** 使用迁移来创建数据库及其表,例如,通过从程序包管理器控制台中运行“ Update-Database”命令。**
Try using this putting in your global.asax 尝试在您的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. 从生产数据库中删除表__MigrationHistory
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.