django South 破坏了我的数据库(无法删除约束)
我想向该表添加一个表和一个外键。最初我有:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
啊,我想桌子被锁了或者什么的。我重新启动了 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.