简体   繁体   English

如何在忽略未决更改的同时在 EF Core 代码优先中生成空迁移?

[英]How to generate empty migration in EF Core code-first while ignoring pending changes?

I am aware that the add-migration command will generate a new migration file with empty Up() and Down() methods.我知道add-migration命令将生成一个新的迁移文件,其中包含空的Up()Down()方法。

However, I have an error when building which means the migration doesn't get created.但是,构建时出现错误,这意味着未创建迁移。

How do I just create a legitimate migration file in spite of the build error?尽管存在构建错误,我如何创建一个合法的迁移文件?

I want to ignore the error and just create an empty migration file because I need to rename a table and column 'manually' (neither of which have corresponding Models in the code).我想忽略该错误并只创建一个空的迁移文件,因为我需要“手动”重命名表和列(它们在代码中都没有相应的模型)。

I want to do this using migrations to ensure all other team members apply the same changes automatically.我想使用迁移来做到这一点,以确保所有其他团队成员自动应用相同的更改。

So I can't create a blank migration because of the error and I can't fix the error (using SQL in a migration) because I can't create a migration file.因此,由于错误,我无法创建空白迁移,也无法修复错误(在迁移中使用 SQL),因为我无法创建迁移文件。

Creating a migration without building is dangerous.在不构建的情况下创建迁移是危险的。 The tools need to know the current state of the model. If a stale, interim model is used, the next migration will probably be wrong and getting everything back in sync won't be easy.这些工具需要知道 model 的当前 state。如果使用过时的临时 model,下一次迁移可能会出错并且让所有内容恢复同步并不容易。

Fix the error before generating a migration--especially if it's an error with your EF Core mode.在生成迁移之前修复错误——特别是如果它是您的 EF Core 模式的错误。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM