Home > Software design >  django/mysql table not found - django.db.utils.ProgrammingError: (1146, "Table 'trustline.
django/mysql table not found - django.db.utils.ProgrammingError: (1146, "Table 'trustline.

Time:05-19

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 error

CodePudding user response:

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.
  • Related