如何在 EF core 6 中手动删除迁移(我没有 Migrations/ts_migrationfile.cs)?

发布于 2025-01-12 15:45:30 字数 1244 浏览 0 评论 0原文

我在迁移时遇到问题,该迁移似乎已被 EF core 错误删除。 它说我必须手动删除一些文件,因为找不到迁移文件,但我找不到关于如何删除它的指南。

  1. 我进行了初始创建迁移
  2. 我添加了一个新迁移,用于在表中创建更多列
  3. 我没有意识到 mi 项目设置为 pgsql 而不是 sqlite
  4. 我删除了迁移(从未应用数据库更新)
  5. Ef core delete 命令已删除./Data/Migrations 上的迁移文件
  6. 我设置了 sqlite
  7. 我添加了新的迁移
  8. 新的迁移再次位于 pgsql 上
  9. 删除迁移尝试删除(步骤 2)迁移而不是(步骤 6)迁移并失败。

它说找不到名为“20220308_Migration2.cs”的文件。 您必须手动删除迁移类“Migration2”,因此出现了问题。

我用于添加、删除和列出迁移的命令如下:

dotnet ef migrations add name -c MyContext -p .\Project.Db\Project.Db.csproj -o .Project.Db\Data\Migrations -s .\Project.Server\Project.Server.csproj

dotnet ef migrations delete name -c MyContext -p .\Project.Db\Project.Db.csproj -s .\Project.Server\Project.Server.csproj

dotnet ef migrations delete name -c MyContext -p .\Project.Db\Project.Db.csproj -s .\Project.Server\Project.Server.csproj

完成后,如果我执行 list 命令,输出将显示:

Migration1 (pending)
Migration2 (pending)

其中 Migration1 是初始创建,Migration2 是在步骤 2 上应用的迁移。

我在 Data/Migrations 文件夹中的文件是与 Migration1 和 Migration3 对应的文件(步骤 6)

另一个问题。

list命令数据从哪里来?是否有秘密数据库或隐藏的缓存文件夹?

如果我只删除 Data/Migrations 文件夹,我可以重新开始迁移吗?

谢谢

I'm having trouble with a migration that seems to have been wrongly deleted by EF core.
It says I have to manually delete some file, since the migration file was not found, but I can't find a guide on how I'm supposed to delete that.

  1. I had my initial create migration
  2. I added a new one for creating a couple more columns in a table
  3. I didn't realize that mi project was set to pgsql instead of sqlite
  4. I deleted the migration (never applied database update)
  5. Ef core delete command deleted the migration files on ./Data/Migrations
  6. I set sqlite
  7. I added a new migration
  8. The new migration was on pgsql again
  9. Delete migration tries to delete the (step 2) migration instead of (step 6) migration and fails.

It says No file named '20220308_Migration2.cs' was found. You must manually remove the migration class 'Migration2', hence the question.

My commands for adding and removing and listing the migrations were the followings:

dotnet ef migrations add name -c MyContext -p .\Project.Db\Project.Db.csproj -o .Project.Db\Data\Migrations -s .\Project.Server\Project.Server.csproj

dotnet ef migrations delete name -c MyContext -p .\Project.Db\Project.Db.csproj -s .\Project.Server\Project.Server.csproj

dotnet ef migrations delete name -c MyContext -p .\Project.Db\Project.Db.csproj -s .\Project.Server\Project.Server.csproj

After all done, if I execute the list command, output shows:

Migration1 (pending)
Migration2 (pending)

Where Migration1 is the initial create and Migration2 is the migration applied on step2.

The files I have on Data/Migrations folder are the ones corresponding to Migration1 and Migration3 (step 6)

Another questions.

Where does the list command data comes from? is there a secret database or a hidden caché folder?

If I just delete the Data/Migrations folder, will I be able to start over with the migrations?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光磨忆 2025-01-19 15:45:30

我的问题是项目之间的沟通。我之前没有提到我的解决方案在项目之间分开(正如您可以通过命令看到的),并且碰巧这些项目通过硬链接(微软的 mklink -h)相互链接到编译后的 de .dll层项目。

发生的情况是,DB 项目和 Server 项目之间的硬链接失败了,因此 Server 项目不知道 Db 项目上的更改,它只能看到硬链接失败时的 DB 项目。

我最终删除了引用并重新添加了它。我一这样做,项目就认识到了迁移的真实状态,一切都很顺利。

所以(回答我的问题),该消息告诉我删除 ./Data/Migrations 中的迁移文件。该文件已被删除,但服务器项目看不到该文件。

“缓存”实际上是引用旧版本数据库项目的损坏的硬链接。 list 命令扫描文件夹 -/Data/Migrations 并与数据库进行比较。

My problem was on communication between projects. I failed to mention before that I have my solution splitted between projects (as you can see by the commands), and happens that those projects are linked to each other by hard links (Microsoft's mklink -h) to de .dll of the compiled lower layer project.

What happened was that somehow the hardlink between the DB project and the Server project failed, so the Server project was not aware about the changes on the Db project, and it could only see the DB project as it was at the moments the hard link failed.

I finally deleted the reference and added it again. As soon as I did that, the project recognized the real state of the migrations and everything went smoothly.

So (answering my questions), the message was telling me to delete the migration file in ./Data/Migrations. The file was deleted, but the Server project could not see that.

The "cache" was actually the broken hard-link that referenced an old version of the DB project. The list command scans the folder -/Data/Migrations and compares with the database.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文