[Django]-Django/mysql table not found – django.db.utils.ProgrammingError: (1146, "Table 'trustline.authentication_user' doesn't exist")

4👍

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.
👤AKX

Leave a comment