【发布时间】:2014-09-22 18:06:42
【问题描述】:
如何使用 EF6 重新创建数据库?
我已经尝试了以下两个帖子,但我不知道为什么它不起作用并出现相同的错误。
- How do I generate an EF6 database with migrations enabled, without using update-database?
- Migrations is enabled for context ''but the database does not exist or contains no mapped tables
我已经在网络服务器上发布了我的示例。我正在使用 Sql Server 2012 Express DBMS。
当我创建我的应用程序并将其发布到 Web 服务器上时,它运行良好。它已自动创建数据库。之后我在ApplicationDBContext 中进行了一些更改,并在IdentityModes(ApplicationUser) 中添加了一些属性。然后我在我的 Local IIS Express 上迁移了数据库,它工作正常。然后我尝试在 Web 服务器上再次发布我的示例,但是这次它显示了一个错误。
Migrations is enabled for context 'ApplicationDbContext' 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.
我已删除网络服务器上的数据库并再次尝试。但是,我仍然面临同样的错误。现在,有一个没有表的空数据库。
应用程序正在创建用户注册数据库。
我也读过这个 post 并尝试调用 dbContext.Database.Initialize(true); 和 ((IObjectContextAdapter)myContext).ObjectContext.CreateDatabase() 方法,但仍然无法正常工作。
【问题讨论】:
标签: asp.net-mvc entity-framework-6 database-migration