SOUTH 和 django 迁移出现错误

发布于 2024-11-18 11:52:18 字数 399 浏览 2 评论 0原文

我在 django 中迁移 Sentry 应用程序时遇到此错误。我正在使用 mysql

 ! Since you have a database that does not support running
 ! schema-altering statements in transactions, we have had
 ! to leave it in an interim state between migrations.

! You *might* be able to recover with:   = DROP TABLE `sentry_groupedmessage` CASCADE; []
   = DROP TABLE `sentry_message` CASCADE; []

我该怎么办

I got this error while migrating Sentry app in django. I am using mysql

 ! Since you have a database that does not support running
 ! schema-altering statements in transactions, we have had
 ! to leave it in an interim state between migrations.

! You *might* be able to recover with:   = DROP TABLE `sentry_groupedmessage` CASCADE; []
   = DROP TABLE `sentry_message` CASCADE; []

what should i do

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

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

发布评论

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

评论(2

听不够的曲调 2024-11-25 11:52:18

您的问题是迁移失败,并且 MySQL 不支持事务,因此 South 不知道表处于哪种状态。

此时恢复它的唯一方法是:

  • 检查表并签入它们处于哪种迁移状态(哪些列发生了更改等)
  • 备份两个表(将它们转储出来)
  • 删除表。
  • 使用 migrate 命令重新创建表。
  • 如果迁移尚未成功,请使用 South 转到表与转储数据的架构匹配的状态
  • 导入转储
  • 再次迁移

Your problem is that the migration failed, and MySQL does not have support for Transactions, so South doesn't know in which state the tables are in.

The only way how you can recover it from this point is:

  • Inspect the tables and check in which state of the migration they are (which columns changed etc)
  • Backup both tables (Dump them out)
  • Delete the tables.
  • Recreate the tables using the migrate command.
  • If the migration was not successful yet, use south to go the a state where the table matches the schema of your dumped-out data
  • Import your dump
  • Migrate again
萌面超妹 2024-11-25 11:52:18

除了托马斯的回答之外;如果您在重新运行迁移期间遇到密钥 content_type_id 的任何 IntegrityError,还请删除专门为应用程序模型创建的权限。该错误类似于以下内容:

IntegrityError: (1062, "Duplicate entry '209-view_' for key 'content_type_id'")

在这种情况下,请从表中删除这些权限auth_permission。您可以对模型名称进行类似搜索,以查找所有权限(查看、添加、更改、删​​除)。

Select * from auth_permission where codename like '%'

上面的命令将为您获取模型的所有权限,您可以获取它们的 ID 并删除(或简单地编写一个连接)。

Additional to Thomas's answer; If you are getting any IntegrityError for a key content_type_id during the re-run of the migration, also remove the permissions that are created specifically for models of the application. The error would be similar to the following:

IntegrityError: (1062, "Duplicate entry '209-view_<model name>' for key 'content_type_id'")

In that case, remove these permissions from the table auth_permission. You can do a like search for your models name to find all the permissions (view, add, change, remove).

Select * from auth_permission where codename like '%<model name>'

The command above will get you all the permission for your model, you can get their ID and delete (or simply write a join).

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