[英]Add-Migration while there are explicit migrations pending
So I have a basic problem trying to generate a migration when I don't have a DB in sync (up to the latest migration, in fact, have no DB at all) and have already made substantial changes to my model. 因此,当我没有DB同步时(直到最新的迁移,实际上根本没有DB)并且已经对我的模型进行了实质性更改,我在尝试生成迁移时遇到了一个基本问题。
This are the specific details: 这是具体细节:
I realize that after the failure in #5 I can now run #4. 我意识到在#5失败后我现在可以运行#4。 Then re-try #5 and voilá.
然后重新尝试#5和voilá。
My Question is if this is the expected approach to solve this silly situation. 我的问题是,如果这是解决这种愚蠢局面的预期方法。
I would use the following approach. 我会使用以下方法。
First you need to apply migrations and specify the last one. 首先,您需要应用迁移并指定最后一个。
PM> Update-Database -TargetMigration AnyMigrationName
# It updates database to a migration named "AnyMigrationName"
# This will apply migrations if the target hasn't been applied or roll back migrations
# if it has
When your local database is updated you simply add new migration. 更新本地数据库后,只需添加新迁移即可。
PM> Add-Migration NewMigrationName
# it scaffolds a new migration named "NewMigrationName"
Looking for a good reference I found these blog posts about EF Migrations that can help you a lot. 寻找一个很好的参考我发现这些关于EF迁移的博客文章可以帮助你很多。 They cover many questions and EF Migrations and a Merge Conflict and EF Migrations Command Reference in particular.
它们涵盖了许多问题,特别是EF迁移和合并冲突以及EF迁移命令参考 。
this error is shown when you have many Migrations pending. 当您有许多待迁移的迁移时,会显示此错误。
If you don't need existing migrations, first delete (exclude) all migration on Migration folder and then add a new migration.
如果您不需要现有迁移,请首先删除(排除)迁移文件夹上的所有迁移,然后添加新迁移。
Add-Migration new
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.