如何改变南迁顺序

发布于 2024-12-27 12:39:56 字数 564 浏览 3 评论 0原文

我的 store 应用程序中有大约 50 个迁移,其中一些是 schemamigration 和一些 datamigration。现在我想在 0037_some_values_to_objects 之前运行 0039_add_column_is_worldwide。所以我更改了名称 0037_add_column_is_worldwide0039_some_values_to_objects

当我为新数据库执行 syncdb 时,它工作正常,但在现有数据库中进行新迁移时,它会出现此错误。

引发异常。不一致的迁移历史记录(问题) Southern.Exceptions.InconcientMigrationHistory:不一致的迁移历史 可以使用以下选项: --merge:将仅尝试迁移,忽略任何潜在的依赖冲突。

我不想丢失数据,那么是否有办法更改这些迁移的顺序?

I have around fifty migrations in my store app, some of them are schemamigration and some datamigration. Now i want to run 0039_add_column_is_worldwide before 0037_some_values_to_objects. So I changed there name 0037_add_column_is_worldwide and 0039_some_values_to_objects.

It works fine when i did syncdb for new db but while migrating for a new migration in existing db it gives this error.

raise exceptions.InconsistentMigrationHistory(problems)
south.exceptions.InconsistentMigrationHistory: Inconsistent migration history
The following options are available:
--merge: will just attempt the migration ignoring any potential dependency conflicts.

I didn't want to lose my data, so is there anyway to change the order of these migrations?

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

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

发布评论

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

评论(2

醉殇 2025-01-03 12:39:56

运行时迁移存储在数据库中,因此如果您已经应用了这些迁移,南边将会迷路。您的替代方案:

  • 刷新迁移表(如果您调用 migrate,将导致所有迁移再次运行)
  • 回滚这些迁移(重命名之前)
  • 伪造这些迁移(migrate --fake,但数字可能与数据库中的数字冲突)

回滚似乎对我来说最安全的是,确保项目中的每个人都这样做。

如果您仍处于开发阶段并且没有产品数据库,您始终可以从零重新启动:

  • 刷新南数据库
  • 迁移 --fake

Migration are stored in DB when ran, so if you already applied these migrations south is going to get lost. Your alternatives:

  • flush the migration table (will cause all migration to run again if you call migrate)
  • rollback these migrations (before renaming)
  • fake these migrations (migrate --fake, but the numbers may conflict with the one in DB anyway)

Rollback seems the safest to me, just be sure everybody in your project do the same.

If you are still in dev and you have no prod database, you can always restart from zero:

  • flush the south db
  • migrate --fake
许你一世情深 2025-01-03 12:39:56

我猜你的数据库已经完成了“0037_some_values_to_objects”。

我会这样做:

删除“0037_some_values_to_objects”中的forward()和其他方法内的代码。此迁移没有任何作用。现在添加两个新的迁移。

经验法则:如果一个系统已完成迁移,请勿将其删除。让它空起来。

I guess your database has already done "0037_some_values_to_objects".

I would do it like this:

Remove the code inside the forward() and other method in "0037_some_values_to_objects". This migration does nothing. Now add two new migrations.

Rule of thumb: If one system has done a migration, don't delete it. Make it empty.

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