projects.blacklist: 'pro_cont' has a relation with model <class 'projects.models.Project_pro_contract'>, which has either not been installed or is abstract.
关系:
一个多对多关系中间表:
class Project_pro_contract(models.Model):
id = models.AutoField('id',primary_key = True)
project_id = models.IntegerField('project_id')
contract_id = models.IntegerField('contract_id')
class Meta:
#app_label = "blacklist"
db_table = 'project_pro_contract'
verbose_name = 'ManyToMany中间表'
verbose_name_plural = verbose_name
ordering = ['-id']
现在新建一个表blacklist直接关联project_pro_contract:
class Blacklist(models.Model):
id = models.AutoField('id',primary_key = True)
pro_cont = models.ForeignKey('Project_pro_contract',db_column = 'pro_cont',null = False,verbose_name = '项目')
blackin = models.BooleanField('黑名', default=False,editable=False)
is_black = models.IntegerField('黑名',default = 0,editable =False)
def __unicode__(self):
return u'%s-%s-%s'%(self.pro_cont.project_id.proj_num,self.pro_cont.project_id.proj_name,self.pro_cont.project_id.invest)
class Meta:
#app_label = "blacklist"
db_table = 'blacklist'
verbose_name = '黑名单'
verbose_name_plural = verbose_name
ordering = ['pro_cont']
syncdb会报错:
CommandError: One or more models did not validate:
projects.blacklist: 'pro_cont' has a relation with model <class 'projects.models.Project_pro_contract'>, which has either not been installed or is abstract.
只要将两个model中注释的语句解除注释即可。
理由见 https://docs.djangoproject.com/en/dev/ref/models/options/