I had the same issue when trying to migrate our models from scratch (especially when testing builds). Upon further investigation, it turned out that we have custom codes related to ContentTypes
model which is associated with the django_content_type
table:
staff_content_types = ContentType.objects.filter(model__in=ACCOUNT_STAFF_APPS)
Then, in our succeeding codes that will access the staff_content_types
variable, it will throw the django.db.utils.ProgrammingError: Table 'django_content_type' doesn't exist
message. Apparently, it tries to access the django_content_type
table which is yet to be built. And our code are based in the context that our data are already setup.
So, there are at least 2 workarounds possible. The idea is to run our custom ContentType-related logic only when our site has already data (after the migration phase):
Catch the error which happens during migration and ignore it:
from django.db.utils import ProgrammingError
try:
for content_type in staff_content_types:
# Our custom codes here.
except ProgrammingError:
pass
Proceed only if django_content_type
table exists (which is the state after migration):
from django.db import connection
if 'django_content_type' in connection.introspection.table_names():
for content_type in staff_content_types:
# Our custom codes here.
Likewise, 3rd-party apps that utilize the Django ContentType
objects/table might have similar issues. So, either you disable them or requests their authors to patch their contrib apps w/ the ideas suggested here.
auditlog
means here. Thank a lot! – Andress