django - 将字段添加到 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”。我该如何解决这个问题?谢谢
解决方案
from ..account.models import User
account_user = models.ForeignKey(
User,
related_name="products",
on_delete=models.CASCADE)
推荐阅读
- javascript - 函数调用中的延迟加载要求语句?
- c++ - cpp中z3的编译和执行命令?
- docker - FeathersJS 和 Docker 应用程序存在套接字和连接问题
- xml - 如何将 xml 文件“复制”到 PostgreSQL?
- sql-server - 恢复时备份 SQL Server Developer 大喊它启用了数据压缩,仅在企业版上可用
- c - 我的 if 语句与我希望它做的相反
- mysql - AND , OR 子句在 MYSQL 中对我不起作用
- python - 查看字符串是否包含不同数据帧中的子字符串
- amazon-cognito - AWS Cognito - preAuthentication 和 customMessage 触发器
- vue.js - Vue 不使用 Webpack 渲染模板,只考虑运行时构建