0

所以使用南,我想在我的一个模型中添加一个新字段 is_private。

按照教程,更改 models.py 文件后,我应该这样做:

./manage.py schemamigration reconstructions --auto

返回:

 Added field is_private on reconstructions.Reconstruction
Created 0005_auto__add_field_reconstruction_is_private.py. You can now apply this migration with: ./manage.py migrate reconstructions

这是伟大的。现在下一步是,

python manage.py migrate reconstructions

那打印:

- Migrating forwards to 0005_auto__add_field_reconstruction_is_private.
 > reconstructions:0005_auto__add_field_reconstruction_is_private
 - Loading initial data for reconstructions.
No fixtures found.

它似乎在做它的工作。但是当我事后检查字段 is_private 时,Django 给我一个错误:

Cannot resolve keyword 'is_private' into field.

这告诉我南根本没有改变数据库。为什么会这样?

额外信息:模型类:

class Reconstruction(models.Model):
    id = models.CharField(max_length=36, primary_key=True,
                          editable=False)

    uploader = models.ForeignKey(User, blank=True, null=True)
    status = models.TextField(blank=True)
    viewcount = models.IntegerField(default=0)
    error_flag = models.IntegerField(default=0)
    is_done = models.BooleanField(default=False)
    create_date = models.DateTimeField(auto_now=True)
    last_modified_date = models.DateTimeField(auto_now=True)
    is_private = models.BooleanField(default=True)

导致崩溃的代码:

recordings = Recording.objects.filter(is_done=True).filter(is_private=False).order_by('-create_date')
4

1 回答 1

3

观察:您添加is_privateReconstruction,但您正在尝试Recording根据该属性过滤对象。也许这就是问题所在?

于 2012-07-27T14:52:33.610 回答