Django 3.2 makemigrations ProgrammingError: table doesn't exist for abstract model

136 Views Asked by At

I'm currently updating my website to use Django 3.2, but I use the zinnia blog which is no longer receiving updates. I'm making the necessary changes to bring it up to compatibility with 3.2 but I'm now getting the error that the AbstractEntry table doesn't exist. This is, however, an abstract table so I'm confused why it would try to find the table at all.

Full traceback:

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.8/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.8/dist-packages/django/core/management/__init__.py", line 357, in execute
    django.setup()
  File "/usr/local/lib/python3.8/dist-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python3.8/dist-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/usr/local/lib/python3.8/dist-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/local/lib/python3.8/dist-packages/zinnia/models/__init__.py", line 4, in <module>
    from zinnia.models.entry import Entry
  File "/usr/local/lib/python3.8/dist-packages/zinnia/models/entry.py", line 6, in <module>
    class Entry(load_model_class(ENTRY_BASE_MODEL)):
  File "/usr/local/lib/python3.8/dist-packages/zinnia/models_bases/__init__.py", line 18, in load_model_class
    _class = getattr(import_module(module_name), class_name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/usr/local/lib/python3.8/dist-packages/zinnia/models_bases/entry.py", line 552, in <module>
    class AbstractEntry(
  File "/usr/local/lib/python3.8/dist-packages/django/db/models/base.py", line 273, in __new__
    new_class.add_to_class(field.name, new_field)
  File "/usr/local/lib/python3.8/dist-packages/django/db/models/base.py", line 321, in add_to_class
    value.contribute_to_class(cls, name)
  File "/usr/local/lib/python3.8/dist-packages/tagging/fields.py", line 26, in contribute_to_class
    super(TagField, self).contribute_to_class(cls, name)
  File "/usr/local/lib/python3.8/dist-packages/django/db/models/fields/__init__.py", line 743, in contribute_to_class
    if not getattr(cls, self.attname, None):
  File "/usr/local/lib/python3.8/dist-packages/tagging/fields.py", line 55, in __get__
    return edit_string_for_tags(Tag.objects.usage_for_model(owner))
  File "/usr/local/lib/python3.8/dist-packages/tagging/models.py", line 160, in usage_for_model
    usage = self.usage_for_queryset(queryset, counts, min_count)
  File "/usr/local/lib/python3.8/dist-packages/tagging/models.py", line 185, in usage_for_queryset
    return self._get_usage(queryset.model, counts, min_count,
  File "/usr/local/lib/python3.8/dist-packages/tagging/models.py", line 125, in _get_usage
    cursor.execute(query % (extra_joins, extra_criteria, min_count_sql),
  File "/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.8/dist-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.8/dist-packages/django/db/backends/mysql/base.py", line 71, in execute
    return self.cursor.execute(query, args)
  File "/usr/local/lib/python3.8/dist-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/usr/local/lib/python3.8/dist-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/usr/local/lib/python3.8/dist-packages/MySQLdb/connections.py", line 259, in query
    _mysql.connection.query(self, query)
django.db.utils.ProgrammingError: (1146, "Table 'somesmart_django.zinnia_abstractentry' doesn't exist")
root@server:/home/scott/somesmart# python manage.py makemigrations zinnia
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.8/dist-packages/django/db/backends/mysql/base.py", line 71, in execute
    return self.cursor.execute(query, args)
  File "/usr/local/lib/python3.8/dist-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/usr/local/lib/python3.8/dist-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/usr/local/lib/python3.8/dist-packages/MySQLdb/connections.py", line 259, in query
    _mysql.connection.query(self, query)
MySQLdb._exceptions.ProgrammingError: (1146, "Table 'somesmart_django.zinnia_abstractentry' doesn't exist")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.8/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.8/dist-packages/django/core/management/__init__.py", line 357, in execute
    django.setup()
  File "/usr/local/lib/python3.8/dist-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python3.8/dist-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/usr/local/lib/python3.8/dist-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/local/lib/python3.8/dist-packages/zinnia/models/__init__.py", line 4, in <module>
    from zinnia.models.entry import Entry
  File "/usr/local/lib/python3.8/dist-packages/zinnia/models/entry.py", line 6, in <module>
    class Entry(load_model_class(ENTRY_BASE_MODEL)):
  File "/usr/local/lib/python3.8/dist-packages/zinnia/models_bases/__init__.py", line 18, in load_model_class
    _class = getattr(import_module(module_name), class_name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/usr/local/lib/python3.8/dist-packages/zinnia/models_bases/entry.py", line 552, in <module>
    class AbstractEntry(
  File "/usr/local/lib/python3.8/dist-packages/django/db/models/base.py", line 273, in __new__
    new_class.add_to_class(field.name, new_field)
  File "/usr/local/lib/python3.8/dist-packages/django/db/models/base.py", line 321, in add_to_class
    value.contribute_to_class(cls, name)
  File "/usr/local/lib/python3.8/dist-packages/tagging/fields.py", line 26, in contribute_to_class
    super(TagField, self).contribute_to_class(cls, name)
  File "/usr/local/lib/python3.8/dist-packages/django/db/models/fields/__init__.py", line 743, in contribute_to_class
    if not getattr(cls, self.attname, None):
  File "/usr/local/lib/python3.8/dist-packages/tagging/fields.py", line 55, in __get__
    return edit_string_for_tags(Tag.objects.usage_for_model(owner))
  File "/usr/local/lib/python3.8/dist-packages/tagging/models.py", line 160, in usage_for_model
    usage = self.usage_for_queryset(queryset, counts, min_count)
  File "/usr/local/lib/python3.8/dist-packages/tagging/models.py", line 185, in usage_for_queryset
    return self._get_usage(queryset.model, counts, min_count,
  File "/usr/local/lib/python3.8/dist-packages/tagging/models.py", line 125, in _get_usage
    cursor.execute(query % (extra_joins, extra_criteria, min_count_sql),
  File "/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.8/dist-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.8/dist-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.8/dist-packages/django/db/backends/mysql/base.py", line 71, in execute
    return self.cursor.execute(query, args)
  File "/usr/local/lib/python3.8/dist-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/usr/local/lib/python3.8/dist-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/usr/local/lib/python3.8/dist-packages/MySQLdb/connections.py", line 259, in query
    _mysql.connection.query(self, query)
django.db.utils.ProgrammingError: (1146, "Table 'somesmart_django.zinnia_abstractentry' doesn't exist")

The abstract entry model:

class AbstractEntry(
        CoreEntry,
        ContentEntry,
        DiscussionsEntry,
        RelatedEntry,
        LeadEntry,
        ExcerptEntry,
        ImageEntry,
        FeaturedEntry,
        AuthorsEntry,
        CategoriesEntry,
        TagsEntry,
        LoginRequiredEntry,
        PasswordRequiredEntry,
        ContentTemplateEntry,
        DetailTemplateEntry):
    """
    Final abstract entry model class assembling
    all the abstract entry model classes into a single one.

    In this manner we can override some fields without
    reimplemting all the AbstractEntry.
    """

    class Meta(CoreEntry.Meta):
        abstract = True
        managed = False
1

There are 1 best solutions below

3
On

In Meta class you have to specify managed=False to prevent orm creation

https://docs.djangoproject.com/en/3.2/ref/models/options/#managed