新手在这里,我试图在Django中建立一个简单的ForeignKey关系。 肉< - 牛肉< - 营养数据。我一直收到错误
<class 'foods_data.models.Nutrition_Data'> has no ForeignKey to <class'foods_data.models.Nutrition_Data'>
这是我的型号代码。
from django.db import models
# Create your models here.
class Category(models.Model):
cat_name = models.CharField(max_length = 200)
def __unicode__(self):
return self.cat_name
class Food_Item(models.Model):
category = models.ForeignKey(Category)
food_name = models.CharField(max_length = 200)
def __unicode__(self):
return self.food_name
class Nutrition_Data(models.Model):
food_item = models.ForeignKey(Food_Item)
nut_name = models.CharField(max_length = 50)
nut_amount = models.IntegerField(default=0)
def __unicode__(self):
return self.nut_name