简体   繁体   English

发布的Asp.net MVC IIS上的实体框架代码优先迁移错误

[英]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: 我最近有同样的问题,我这样解决了:

  1. In the constructor of your Configuration class turn off the migration: 在您的Configuration类的构造函数中,关闭迁移:

public Configuration() { AutomaticMigrationsEnabled = false; }

  1. Drop the table __MigrationHistory from your production database. 从生产数据库中删除表__MigrationHistory

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 代码优先实体框架Asp.net MVC - Code First Entity Framework Asp.net MVC 具有实体框架代码优先导航属性的ASP.Net MVC - ASP.Net MVC with Entity Framework Code First Navigation Property 在ASP.NET MVC项目中使用实体框架代码优先时登录失败错误 - Login failed error when using Entity Framework code-first in ASP.NET MVC project 带实体框架的ASP.NET Core-代码优先迁移未读取我的环境变量 - ASP.NET Core with Entity Framework - code first migrations aren't reading my environment variables 空迁移首先在代码中生成ASP.NET MVC - Empty Migrations are generated in code first ASP.NET MVC ASP.NET MVC 代码优先构建空迁移 - ASP.NET MVC Code-First Building Empty Migrations 在没有实体框架和迁移的ASP.NET Core MVC应用程序中使用ASP.NET标识 - Using ASP.NET Identity in an ASP.NET Core MVC application without Entity Framework and Migrations 使用实体框架的代码优先方法在ASP.NET MVC应用程序中缺少外键关系 - Foreign key relationship missing in ASP.NET MVC app using code-first approach with Entity Framework ASP.NET MVC实体框架的代码优先:没有错误,但表未正确填充 - ASP.NET MVC Entity Framework code-first: no errors but tables aren't populated correctly 如何使用“代码优先实体框架”在ASP.NET MVC 4中创建数据库并将其连接到数据库? - How to create a database and connect to it in ASP.NET MVC 4 by using Code First Entity Framework?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM