我正在尝试从elements.models导入一个类,我需要在另一个类上作为foreignkey。问题是,我得到一个我不理解的长错误列表。没有这条线,一切都很完美。
我导入线的模型
from django.db import models
from elements.models import Region
class Character(models.Model):
""" User characters that hold the personal game stats """
created = models.DateTimeField(auto_now_add=True)
alive = models.BooleanField(default=True)
name = models.CharField(max_length=63, unique=True)
xp = models.IntegerField(default=0)
region = models.ForeignKey(Region)
alliance = models.ForeignKey('Alliance', null=True)
credit = models.IntegerField(default=0)
bullets = models.IntegerField(default=0)
hitpoints = models.IntegerField()
accuracy = models.FloatField(default=0)
def __unicode__(self):
return self.name
elements.models Region class:
class Region(models.Model):
""" type of booze and their base price """
name = models.CharField(max_length=31, unique=True)
alliance_slots = models.IntegerField()
def __unicode__(self):
return self.name
现在,当我尝试同步数据库时,我得到以下错误列表
任何想法是什么原因造成的?
答案 0 :(得分:1)
您可能正在进行循环导入。在导入包含Region类的models.py文件中的Character类时,您将导入包含Character类的models.py文件中的Region类。
尝试用此
替换您的Character类from django.db import models
class Character(models.Model):
""" User characters that hold the personal game stats """
created = models.DateTimeField(auto_now_add=True)
alive = models.BooleanField(default=True)
name = models.CharField(max_length=63, unique=True)
xp = models.IntegerField(default=0)
region = models.ForeignKey('elements.Region')
alliance = models.ForeignKey('Alliance', null=True)
credit = models.IntegerField(default=0)
bullets = models.IntegerField(default=0)
hitpoints = models.IntegerField()
accuracy = models.FloatField(default=0)
def __unicode__(self):
return self.name