简体   繁体   English

在显式迁移挂起时添加迁移

[英]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: 这是具体细节:

  1. Have a sequence of explicit migrations. 有一系列显式迁移。
  2. Have no database. 没有数据库。 In short, have lots of pending changes. 简而言之,有许多待定的更改。
  3. Made changes to the models/context. 对模型/上下文进行了更改。
  4. When trying to Add-Migration, it will complain saying precisely that explicit migrations are pending . 在尝试添加迁移时,它会抱怨说明确的迁移是未决的
  5. If I try to execute the migration (and bring my DB in sync), either via Update-Database or migrate.exe, it will fail (after applying explicit migrations successfully), and automatic migrations are not enabled. 如果我尝试通过Update-Database或migrate.exe执行迁移(并使我的数据库同步),它将失败(成功应用显式迁移后), 并且未启用自动迁移。
  6. I don't want to enable automatic migrations either (to prevent any schema changes to be committed and go unaccounted in code.) 我也不想启用自动迁移 (以防止提交任何架构更改并在代码中取消计算。)

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.

相关问题 如何在使用基于代码的迁移时停止添加迁移检查我的数据库没有挂起的迁移? - How can I stop Add-Migration checking my database has no pending migrations when using Code-Based migrations? 无法生成显式迁移,因为以下显式迁移待处理 - Unable to generate an explicit migration because the following explicit migrations are pending 启用迁移已过时。 使用 Add-Migration 开始使用 Migrations - Enable-Migrations is obsolete. Use Add-Migration to start using Migrations 添加迁移异常 - Add-migration Exeception 实体框架:将迁移类移动到迁移文件夹后,从挂起的显式迁移列表中丢失迁移类 - Entity Framework: Migration classes missing from list of pending explicit migrations after moving them to the migrations folder 进行添加迁移时,EntityFramework核心模型关系问题 - EntityFramework core model relationship issue while doing Add-Migration 添加迁移ef core 2预览1时出错 - Error while Add-Migration ef core 2 preview 1 在程序集''中找到了多个迁移配置类型。 指定要使用的名称。 在添加迁移 - More than one migrations configuration type was found in the assembly ''. Specify the name of the one to use. On add-migration 添加迁移不适用于 MySQL - Add-Migration not working with MySQL 添加迁移:部分结果 - Add-Migration: Partial results
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM