首页 > 解决方案 > 将字段添加到 Django 模型

问题描述

我正在做这个项目:https ://github.com/mirumee/saleor

我想在产品表中添加一个“user_id”列。因此,我将以下代码添加到第 248 行 https://github.com/mirumee/saleor/blob/master/saleor/product/models.py#L248

account_user = models.ForeignKey(
    Account_User,
    related_name="products",
    on_delete=models.CASCADE,
 )

但是,Django 说“NameError: name 'Account_User' is not defined”。我该如何解决这个问题?谢谢

标签: djangosaleor

解决方案


from ..account.models import User

account_user = models.ForeignKey(
User,
related_name="products",
on_delete=models.CASCADE)

推荐阅读