jazzband / wagtailmenus

An app to help you manage and render menus in your Wagtail projects more effectively
MIT License
398 stars 138 forks source link

Django warning (models.w402) on Django 3.2 #396

Closed jams2 closed 3 years ago

jams2 commented 3 years ago

When running the development server on django 3.2, wagtail 2.13, the following warning is shown:

WARNINGS:
wagtailmenus.FlatMenu: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
    HINT: Configure the DEFAULT_AUTO_FIELD setting or the WagtailMenusConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
wagtailmenus.FlatMenuItem: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
    HINT: Configure the DEFAULT_AUTO_FIELD setting or the WagtailMenusConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
wagtailmenus.MainMenu: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
    HINT: Configure the DEFAULT_AUTO_FIELD setting or the WagtailMenusConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
wagtailmenus.MainMenuItem: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
    HINT: Configure the DEFAULT_AUTO_FIELD setting or the WagtailMenusConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.

Subclassing WagtailMenusConfig looks like a workaround, e.g.:

class CustomWagtailMenusConfig(WagtailMenusConfig):
    """Fix warning models.W042, regarding auto-created primary keys without a
    defined type.

    https://docs.djangoproject.com/en/3.2/releases/3.2/#customizing-type-of-auto-created-primary-keys
    """
    default_auto_field = "django.db.models.BigAutoField"

Happy to throw together a PR which adds a default_auto_field declaration to WagtailMenusConfig.

Django 3.2 release notes Django apps

jams2 commented 3 years ago

Can also be solved by setting DEFAULT_AUTO_FIELD, closing this.