简体   繁体   English

EF Codefirst迁移新数据库

[英]EF Codefirst Migrations new database

I'm confused as to what to do in the situation I've gotten myself into. 我对自己陷入困境的情况感到困惑。

I've recreated my database after an issue. 发生问题后,我已经重新创建了数据库。 When I run up my project, CodeFirst creates the database from my EF model. 当我运行项目时,CodeFirst通过我的EF模型创建数据库。 The site then works fine. 该站点然后可以正常工作。

But as soon as I come to add a migration, it says I've got explicit migrations pending on my database. 但是,一旦我开始添加迁移,它就表明我的数据库中有待处理的显式迁移。 These pending migrations are ALL existing migrations. 这些挂起的迁移是所有现有迁移。

It appears that my DB has been created with the most recent model. 看来我的数据库是用最新模型创建的。 But without any model/revision data attached. 但不附带任何模型/修订数据。

How do I go about populating that migration data so EF knows the db is up to date? 我该如何填充该迁移数据,以便EF知道数据库是最新的?

I would have to ask, how did you go about resolving the issue you had? 我不得不问,您如何解决您遇到的问题? The idea of migrations is that you can go backwards and forwards through them, allowing you to revert any changes. 迁移的想法是,您可以在它们之间来回移动,从而可以还原所有更改。

That said, you are where you are. 就是说,你在哪里。 In this instance I would have to agree with @sq33G and remove the existing migrations, and fix your current database. 在这种情况下,我必须同意@ sq33G并删除现有的迁移,并修复当前的数据库。 As you haven't provided a comprehensive account of your problem I would suggest that data elsewhere could be imported into your current database if required with SQL queries. 由于您尚未提供有关问题的全面说明,因此我建议,如果SQL查询需要将其他地方的数据导入到当前数据库中。

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

相关问题 EF 6 CodeFirst迁移不起作用 - EF 6 CodeFirst Migrations Not Working EF CodeFirst迁移不起作用 - EF CodeFirst migrations not working 使用Unity配置依赖项注入时,如何防止EF CodeFirst尝试在数据库上运行迁移? - How do I prevent EF CodeFirst from trying to run migrations on my database, when configuring dependency injection with Unity? 如何正确更改程序集中的版本(启用EF CodeFirst迁移)? - How to change version in assembly (with enabled EF CodeFirst migrations) correctly? EF Core 数据库迁移 - EF Core database migrations EF 5, Code First - 创建一个新数据库并以编程方式运行所有迁移 - EF 5, Code First - Create a new database and run all migrations programmatically EF迁移不会自动更新数据库 - EF migrations not updating the database automatically EF Core 3.1:删除了所有迁移和数据库,如何在新数据库中重新创建所有表? - EF Core 3.1: Deleted all Migrations and the Database, how to recreate all tables in a new database? 无法使用新的日期时间值ef代码更新行 - cannot update a row with a new datetime value ef codefirst 在不清除数据的情况下从EF6中的CodeFirst更新数据库 - Update database from CodeFirst in EF6 without wiping out data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM