django South 破坏了我的数据库(无法删除约束)

发布于 2024-10-31 12:17:47 字数 944 浏览 1 评论 0原文

我想向该表添加一个表和一个外键。最初我有:

class VirtualMachine(models.Model):
    ...

然后将其更改为:

class OperatingSystem(models.Model):
    name = models.CharField(max_length=40)

    def __unicode__(self):
        return self.name

class VirtualMachine(models.Model):
    operating_system = models.ForeignKey(OperatingSystem, default=1)

并且我想输入一个条目,这样 1 就是“WindowsXP”。不过,南不喜欢这样,所以我将最后一行更改为:

    operating_system = models.ForeignKey(OperatingSystem, null=True)

效果很好。迁移之后,我添加了“WindowsXP”条目并将其改回:

    operating_system = models.ForeignKey(OperatingSystem, default=1)

我做了python manage.py schemamigration app --auto,效果很好,然后python manage.py migrate app< /code>,冻结了。冻僵了!

我取消了它并进入了 psql。我无法执行 SELECT * FROM app_virtualmachine; - 这会挂起,尽管从其他表中获取内容不会挂起。我什至无法从那里选择一列。我尝试放弃 South 添加的约束,但也没有什么好处。什么给?

I wanted to add a table and a foreign key to that table. Initially I had:

class VirtualMachine(models.Model):
    ...

I then changed that to:

class OperatingSystem(models.Model):
    name = models.CharField(max_length=40)

    def __unicode__(self):
        return self.name

class VirtualMachine(models.Model):
    operating_system = models.ForeignKey(OperatingSystem, default=1)

and I wanted to make an entry so that 1 would be "WindowsXP". South didn't like that, though, so I changed the last line to:

    operating_system = models.ForeignKey(OperatingSystem, null=True)

That worked ok. After that migration I added the "WindowsXP" entry and changed it back to:

    operating_system = models.ForeignKey(OperatingSystem, default=1)

I did python manage.py schemamigration app --auto, which worked fine, then python manage.py migrate app, which froze. Froze!

I cancelled it and went into psql. I couldn't do SELECT * FROM app_virtualmachine; - that would hang, although getting stuff from other tables would not. I couldn't even select just a column from there. I tried dropping the constraint South added but also no good. What gives?

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

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

发布评论

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

评论(1

洒一地阳光 2024-11-07 12:17:47

啊,我想桌子被锁了或者什么的。我重新启动了 postgres,然后可以手动对表执行操作并拯救它。

Ah I think the table got locked or something. I restarted postgres and then could do stuff manually to the table and rescue it.

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