Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Compability] Changes to AutoField with Django 3.2 #80

Open
ckoerber opened this issue Apr 15, 2021 · 1 comment
Open

[Compability] Changes to AutoField with Django 3.2 #80

ckoerber opened this issue Apr 15, 2021 · 1 comment
Assignees

Comments

@ckoerber
Copy link
Member

Description

With the new Django 3.2 version, makemigrations and migrate seem to raise a warning about AutoFields for the notification app.

WARNINGS:
notifications.Notification: (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 NotificationsConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.

To Reproduce

This happens on default when installing the most recent Django version 3.2

pip install Django==3.2
espressodb startproject temp
cd temp
python manage.py migrate

Additional context

Django 3.2 release notes: https://docs.djangoproject.com/en/3.2/releases/3.2/

When defining a model, if no field in a model is defined with primary_key=True an implicit primary key is added. The type of this implicit primary key can now be controlled via the DEFAULT_AUTO_FIELD setting and AppConfig.default_auto_field attribute. No more needing to override primary keys in all models.

Maintaining the historical behavior, the default value for DEFAULT_AUTO_FIELD is AutoField. Starting with 3.2 new projects are generated with DEFAULT_AUTO_FIELD set to BigAutoField. Also, new apps are generated with AppConfig.default_auto_field set to BigAutoField. In a future Django release the default value of DEFAULT_AUTO_FIELD will be changed to BigAutoField.

@ckoerber ckoerber self-assigned this Apr 15, 2021
@ckoerber
Copy link
Member Author

It seems to me that the least intrusive way of fixing this is adding the default_auto_field attribute to the NotificationsConfigApp to point to 'django.db.models.AutoField' or maybe even BigAutoField. Since existing projects use AutoField, I am tending to this one to not cause new migrations for all existing projects. I will implement and test this.

ckoerber added a commit that referenced this issue Apr 15, 2021
This resolves #80. I have verified that this fix removes the warning and 
does not create new migrations for exisiting projects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant