因此,我有两个我正在try 移植的模型.
class Organisation(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=256)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
status = models.CharField(max_length=64,choices=STATUS,default='active')
logo_file_path = models.CharField(max_length=2048)
和
class Team(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=256)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
status = models.CharField(max_length=64,choices=STATUS,default='active')
org_id = models.ForeignKey(Organisation(),to_field=id, on_delete=models.CASCADE)
I need Team.org_id linked to Organisation.id, so I'm trying to use it as a foreign key.
但在try 进行迁移时,它给我带来了以下系统错误:
SystemCheckError: System check identified some issues:
ERRORS:
db_app.Team.org_id: (fields.E312) The to_field 'db_app.Team.id' doesn't exist on the related model 'db_app.Organisation'.
注意:db_app是我的Django应用程序名称.
我猜是外键中的to_field
参数导致了这个问题.不过,我不太确定.
我已经在不同项目的不同型号上try 了它,错误仍然是一样的.