0
我有以下Django模型:Django的许多一对多 '海峡' 对象有没有属性 '_meta'
class Recipe(models.Model):
ingredients = models.ManyToManyField(
'foo.Ingredient',
through='RecipeIngredient',
through_fields=('recipe', 'ingredient')
)
class RecipeIngredient(models.Model):
recipe = models.ForeignKey(Recipe, blank=True, null=True)
ingredient = models.ForeignKey('foo.Ingredient', blank=True, null=True)
将会产生一个错误:
name = model._meta.db_table
AttributeError: 'str' object has no attribute '_meta'
它看起来像ORM可以”找不到foo.Ingredient
模型并对其进行解释像海峡(但ForeginKey
正常工作)
我也尝试过使用through='current.RecipeIngredient
,主要生产:
sec_column = fk.m2m_column_name()
AttributeError: 'ManyToManyField' object has no attribute 'm2m_column_name'
如何解决?
谢谢。
此错误似乎相关:https://code.djangoproject.com/ticket/25292 – knbk
Foo已安装。 – foo
这几乎肯定与上面链接的bug报告有关,该报告仅在5天前关闭。如果可能的话,OP应该更新为绝对最新的Django,如果不是,则可能不得不停止使用'through_fields'。 @knbk应该使该评论成为答案。 –