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

Primary keys with Django 3.2+ #126

Closed
uri-rodberg opened this issue Jan 20, 2021 · 4 comments · Fixed by #146
Closed

Primary keys with Django 3.2+ #126

uri-rodberg opened this issue Jan 20, 2021 · 4 comments · Fixed by #146

Comments

@uri-rodberg
Copy link
Contributor

uri-rodberg commented Jan 20, 2021

Adding DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' in settings creates new migrations for django-friendship with Django 3.2+. I think it's better to define the primary keys to allow big integers in the app and add the migrations. django-friendship may be used in a database where there are more than 2**31 friendship requests or other models, and it's better to use BigAutoField than the default AutoField, and also to define those in the app and not to rely on the site's settings. When relying on settings a migration is created within django-friendship, but this package is installed as it is and should include all its migrations.

If I use django-friendship as it is without defining DEFAULT_AUTO_FIELD in settings, I get these warnings with Django 3.2 alpha:

friendship.Block: (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 AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
friendship.Follow: (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 AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
friendship.Friend: (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 AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
friendship.FriendshipRequest: (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 AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.

Tested with Django 3.2 alpha.

@jefftriplett
Copy link
Member

jefftriplett commented Aug 25, 2021

Now that our trove classifier has been updated for Django 3.2, I wonder what all we need to do to better support this.

@uri-rodberg
Copy link
Contributor Author

uri-rodberg commented Aug 26, 2021

Now that our trove classifier has been updated for Django 3.2, I wonder what all we need to do to better support this.

https://docs.djangoproject.com/en/3.2/releases/3.2/#customizing-type-of-auto-created-primary-keys

Define default_auto_field in AppConfig.
There are advantages to defining it as django.db.models.BigAutoField, since then it will allow more than 2**31 records. Otherwise records will be limited to up to 2**31 (about 2 billion records).

Notice that if there are 10 million users, and each user has 200 friendship requests or 200 friends, then it's already 2 billion records.

And of course, generate and commit the migrations if necessary.

@uri-rodberg
Copy link
Contributor Author

It looks like #146 hasn't been released to production, CHANGELOG.rst not updated so I guess you closed this issue too early.

@uri-rodberg
Copy link
Contributor Author

#159

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

Successfully merging a pull request may close this issue.

2 participants