通过south迁移现有应用程序

2024-03-29 09:41:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下模型-

class ToDo(models.Model):

    todo_title = models.CharField(null=True, blank=True, max_length=200)
    todo_status = models.IntegerField(choices=TASK_STATUS, null=True, blank=True)
    assigned_to = models.ManyToManyField(OrgStaff, null=True, blank=True, related_name='assigned_to')
    assigned_by = models.ManyToManyField(OrgStaff, null=True, blank=True, related_name='assigned_by')
    assigned_time = models.DateTimeField(auto_now_add=True)
    completed_time = models.DateTimeField(null=True, blank=True)

然后运行python manage.py convert_to_south todoapp,其中todoapp是 应用程序。然后我运行python manage.py migrate todoapp.

完成后,我在上述模型中添加另一个字段-

class ToDo(models.Model):

    todo_title = models.CharField(null=True, blank=True, max_length=200)
    todo_slug = models.SlugField(null=True, blank=True)
    todo_status = models.IntegerField(choices=TASK_STATUS, null=True, blank=True)
    assigned_to = models.ManyToManyField(OrgStaff, null=True, blank=True, related_name='assigned_to')
    assigned_by = models.ManyToManyField(OrgStaff, null=True, blank=True, related_name='assigned_by')
    assigned_time = models.DateTimeField(auto_now_add=True)
    completed_time = models.DateTimeField(null=True, blank=True)

现在我做一个模式化-python manage.py schemamigration todoapp --auto,然后python manage.py migrate todoapp这样做会产生以下错误-

Running migrations for taskbase:
 - Migrating forwards to 0002_auto__add_field_todo_todo_slug.
 > taskbase:0002_auto__add_field_todo_todo_slug
KeyError: u'todo_title'

知道我为什么会犯这个错误吗? 我撞了头,但找不到原因。你知道吗


Tags: tonametrueautobytimemodelsnull
1条回答
网友
1楼 · 发布于 2024-03-29 09:41:09

在“标题”和“状态”前面加上“todo”可能会导致与表字段的名称冲突。事实上,在数据库中,Django正在命名todoapp\u todo\u todo\u status字段,South可能会感到困惑。南方在内部做了一些创造性的事情,因此发生了冲突。我建议尝试:

class ToDo(models.Model):

    title = models.CharField(null=True, blank=True, max_length=200)
    status = models.IntegerField(choices=TASK_STATUS, null=True, blank=True)
    assigned_to = models.ManyToManyField(OrgStaff, null=True, blank=True, related_name='assigned_to')
    assigned_by = models.ManyToManyField(OrgStaff, null=True, blank=True, related_name='assigned_by')
    assigned_time = models.DateTimeField(auto_now_add=True)
    completed_time = models.DateTimeField(null=True, blank=True)

我想变得迂腐,我还可以指出,todoapp应该被称为todos,但这对你的项目没有什么不同。你知道吗

相关问题 更多 >