找不到django/mysql表-django.db.utils.programmingerror:(1146,table;

发布于 2025-01-30 13:05:22 字数 473 浏览 6 评论 0原文

我一直在尝试为项目 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

五里雾 2025-02-06 13:05:22

您的错误源于尝试在导入时使用数据库。
在Django中,在应用程序初始化时间期间可能导入的模块级别上使用数据库是一个很大的禁忌需要一张尚未迁移到存在的表...好吧,我们在这里。

查看在实用程序/email_sending.py.py,第27行,get_admin_emails()的调用中,发生的情况。

对于此特定问题,修复程序应该是

  • 删除admin_emails = get_admin_emails()(而只是调用get_admin_emails() >现在)。
  • 而且,如果您想要以前的性能,请拍打@lru_cache@cache decorator get_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 of get_admin_emails().

For this particular problem, the fix should be to

  • remove ADMIN_EMAILS = get_admin_emails() (and instead just call get_admin_emails() wherever you might be using ADMIN_EMAILS right now).
  • and if you want the same performance you had before, slap an @lru_cache or @cache decorator on get_admin_emails() so it ever does its work once.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文