Override Config of Django app, extra django-cms migration is created

Oct. 31, 2021, 6:55 a.m.

Sometimes you need to override Config for various reasons.

For example, in my case, after updating django 3.2+, a migration for django-cms was automatically created when you call makemigrations for your project.

It was in this error that this behavior arose due to the introduction of default_auto_field (see: https://docs.djangoproject.com/en/3.2/ref/applications/#django.apps.AppConfig.default_auto_field) and setting your DEFAULT_AUTO_FIELD to a value other than django.db.models.AutoField, namely django.db.models.BigAutoField. Therefore, when calling makemigrations, a migration was created in which the type of the ID field became BigAutoField for all django-cms models.

To fix the error above, you need to override CMSConfig in any of your applications in any file, but for convention it is better in apps.py:

# spec/apps.py
from cms.apps import CMSConfig as BaseCMSConfig


class CMSConfig(BaseCMSConfig):
    default_auto_field = 'django.db.models.AutoField'

Now replace 'cms' in INSTALLED_APPS:

INSTALLED_APPS = (
    # 'cms',
    'spec.apps.CMSConfig',
)

If you have already run migrate in your project, then you need to return the correct type to the ID fields. To do this, run makemigrations so that the ID field become django.db.models.AutoField again, and apply the migration with the migrate command. Now you can already delete the last two migrations from your project. It is also possible to delete records of applied migrations from the database (although this is not essential).

I think the django-cms developers will add default_auto_field by default, so in your project after updating the django-cms version, check if default_auto_field appears in CMSConfig. If so, return 'cms' to INSTALLED_APPS.

Rate this article

0 from 5 (total 0 ratings)

You can send feedback, suggestions or comments on this article using this form:

Fields marked by star ( * ) is required.

Thank you for yor feedback!

After clicking the "Send" button, your message will be delivered to me on the mail.

Author of Article

Artem Maltsev

Web-developer, having the knowlenge of programming language - Python, framework - Django, content management system - Django CMS, platform of e-commerce site - Django Shop and many other applications, using this technologies.

The right to use content on this page https://vivazzi.pro/it/override-config/:

Permission is granted to copy an content with its author and reference to the original without using the parameter rel="nofollow" in tag <a>. Usage:

Author of Article: Artem Maltsev
Link to article: <a href="https://vivazzi.pro/it/override-config/">https://vivazzi.pro/it/override-config/</a>

More: Terms of site usage

Comments: 0

You can leave a comment as an unregistered user.

But if you sing up, you can:

  • receive notifications
  • view your comments
  • be able to use all the functions of the developed services

To comment in one's own name you should log in or sign up on Vuspace website

Send

There is no search on this site, so I offer to use usual search engine, for example, Google, adding "vivazzi" after your request.

Try it

Select currency for displaying monetary values