【发布时间】:2014-07-28 11:41:35
【问题描述】:
这是我的生产模型(在 selfcare.apps.support.models 中):
class Document(models.Model):
CATEGORY_CHOICES = (
('HSI', _('Internet')),
('ITV', _('Television')),
('VOIP', _('Phone')),
('MAIL', _('Email')),
)
title = models.CharField(max_length=100, db_index=True)
start_date = models.DateTimeField(default=datetime.datetime.now)
end_date = models.DateTimeField(blank=True, null=True)
active = models.BooleanField(default=True)
category = models.CharField(max_length=10, choices=CATEGORY_CHOICES)
document = models.FileField(upload_to='support_documents')
我想在现有的 Document 模型中添加以下行:
network = models.ManyToManyField('selfcare.apps.auth.models.Network')
这是 Network 类的模型(在 selfcare.apps.auth.models 中):
class Network(selfcare.libs.core.utils.SettingHelper, models.Model):
name = models.CharField(max_length=100, db_index=True)
code = models.CharField(max_length=20, db_index=True, default='')
operator = models.ForeignKey(Operator)
setting = generic.GenericRelation(Setting)
def __unicode__(self):
return "%s - %s" % (self.code, self.operator.code)
当我尝试使用 south 进行架构迁移时,我收到以下错误消息:
CommandError: One or more models did not validate:
support.document: 'networks' has an m2m relation with model selfcare.apps.auth.models.Network, which has either not been installed or is abstract.
这两个应用都在 INSTALLED_APP 中。 这两个应用程序都已由南管理。
【问题讨论】:
-
INSTALLED_APPS中到底是什么?请注意,您不应该在该 M2M 字段引用中包含models。 -
selfcare.apps.auth 和 selfcare.apps.support 在 INSTALLED_APPS 中。我已将添加的行更改为 networks = models.ManyToManyField('selfcare.apps.auth.Network') 但结果是一样的
-
将您的应用称为“auth”可能不是一个好主意,因为它与 django.contrib.auth 应用同名。
标签: django django-models django-south