Django models.py中的NameError

时间:2015-08-19 09:13:48

标签: python django django-models

我有5个课程,CustomerSupplierOrderDesignOutSourceOrder有3个关系,一对一与Customer,多对多与Design,一对一与OutSourse。首先我刚刚添加s one to one relationship with客户(customer=models.ForeignKey(Customer)), now I wanna add the those 2 relationships with设计and Outsourse`。

 design=models.ManyToManyField(Design)
 outSource=models.OneToOneField(OutSource)

当我这样做并运行“makemigrations”命令时,我收到此错误 - > “NameError:name”Design“未定义” 如果没有那两行代码,我可以在没有任何问题的情况下进行迁移......无法弄清楚我哪里出错了。 任何帮助将不胜感激。

models.py

class Order(models.Model):
    o_type=models.CharField(max_length=15, verbose_name='Order type')
    number=models.IntegerField()
    date=models.DateField()
    status=models.CharField(max_length=25)
    delivery_date=models.DateField()
    customer=models.ForeignKey(Customer)
    design=models.ManyToManyField(Design)
    outSource=models.OneToOneField(OutSource)

class Design(models.Model):
    dimension=models.IntegerField()
    image=models.ImageField(upload_to='images/%Y/%m/%d')
    number_of_colors=models.IntegerField()
    sides=models.IntegerField(verbose_name='side(s)')

class OutSource(models.Model):
    date=models.DateField()
    number=models.IntegerField()
    description=models.CharField(max_length=100)
    code=models.IntegerField()
    supplier=models.ForeignKey(Supplier)

1 个答案:

答案 0 :(得分:5)

您在实际定义Design关系后声明了课程ManyToManyField。它找不到名为Design的类,因此找不到NameError

在课程Design之前宣布课程Order,事情应该适合你。