找不到django/mysql表-django.db.utils.programmingerror:(1146,table;
我一直在尝试为项目 makemigrations ,但是每当我这样做时,我都会得到此错误:
django.db.utils.programmingerror:(1146,“ table'trustline.authentication_user'不存在”
我在settings.py
中有这一行:
auth_user_model =“ authentication.user”
这是该错误的完整追溯:
I was trying to makemigrations
for my project but whenever I do this, I got this error:
django.db.utils.ProgrammingError: (1146, "Table 'trustline.authentication_user' doesn't exist"
And I have this line in settings.py
:
AUTH_USER_MODEL = "authentication.User"
Here's the full traceback of the error:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的错误源于尝试在导入时使用数据库。
在Django中,在应用程序初始化时间期间可能导入的模块级别上使用数据库是一个很大的禁忌需要一张尚未迁移到存在的表...好吧,我们在这里。
查看在
实用程序/email_sending.py.py
,第27行,get_admin_emails()
的调用中,发生的情况。对于此特定问题,修复程序应该是
admin_emails = get_admin_emails()
(而只是调用get_admin_emails() >现在)。
@lru_cache
或@cache
decoratorget_admin_emails()
在一次。Your error stems from attempting to use the database at import time.
In Django, it's a big no-no to use the database on module level in a module that may be imported during your application's initialization time, since the application needs to be initialized so you can make or run migrations, and if such a database call requires a table that hasn't yet been migrated into existence... well, here we are.
Looking at the traceback, that happens in
utility/email_sending.py
, line 27, an invocation ofget_admin_emails()
.For this particular problem, the fix should be to
ADMIN_EMAILS = get_admin_emails()
(and instead just callget_admin_emails()
wherever you might be usingADMIN_EMAILS
right now).@lru_cache
or@cache
decorator onget_admin_emails()
so it ever does its work once.