bennylope / django-organizations

:couple: Multi-user accounts for Django projects
http://django-organizations.readthedocs.org/
BSD 2-Clause "Simplified" License
1.3k stars 212 forks source link

Set default_auto_field to 'AutoField' #223

Closed simkimsia closed 3 years ago

simkimsia commented 3 years ago

Django 3.2 introduces DEFAULT_AUTO_FIELD . If you set this to something other than 'django.db.models.AutoField', migrations will need to be generated for django-organization's models. This pull request sets default_auto_field just for these apps so that no migrations need to be generated.

It also hides warnings on Django 3.2.

The specific warning is

RemovedInDjango41Warning: 'organizations' defines default_app_config = 'organizations.apps.OrganizationsConfig'. Django now detects this configuration automatically. You can remove default_app_config.
    app_config = AppConfig.create(entry)

Similar in another highly used django library https://github.com/pennersr/django-allauth/pull/2829

EDIT

Change allauth to django-organization

simkimsia commented 3 years ago

For those who are looking for workaround while waiting for the PR #224 to be merged, here's the workaround.

GO to your apps.py in your django project and add this at the end of the file. Do remember to remove it after the PR is merged

from organizations.apps import OrganizationsConfig

class ModifiedOrganizationsConfig(OrganizationsConfig):
    default_auto_field = "django.db.models.AutoField"

in your settings.py where you declare your third_party_apps

THIRD_PARTY_APPS = [
    ...
    # "organizations", # you should comment this out and when the PR is merged, uncomment it
    "yourproject.apps.ModifiedOrganizationsConfig", # remove this when PR is merged
    ....
]

LOCAL_APPS = [
    "yourprojectapp",
]

# https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
bennylope commented 3 years ago

I was very confused by this:

Django 3.2 introduces DEFAULT_AUTO_FIELD . If you set this to something other than 'django.db.models.AutoField', migrations will need to be generated for allauth's models. This pull request sets default_auto_field just for these apps so that no migrations need to be generated.

But that if that reads "django-organization's models" then it makes a lot more sense!

Thank you @simkimsia!

simkimsia commented 3 years ago

But that if that reads "django-organization's models" then it makes a lot more sense!

Oh right.. sorry!

simkimsia commented 3 years ago

@bennylope pls update pypi for a new version if you don't mind. I like to update the dependency so i can stop using the workard i detailed here.

bennylope commented 3 years ago

@simkimsia it's live now, thank you again https://pypi.org/project/django-organizations/#history