#33366: Foreign key to settings.AUTH_USER_MODEL causes hard-coded alteration in migration -------------------------------------+------------------------------------- Reporter: Andrew Chen Wang | Owner: nobody Type: Bug | Status: new Component: Database layer | Version: 4.0 (models, ORM) | Severity: Normal | Resolution: Keywords: | Triage Stage: | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Description changed by Andrew Chen Wang:
Old description: > We have a model in a package called [django-oauth- > toolkit](https://github.com/jazzband/django-oauth- > toolkit/blob/0204383f7b6f8739322f2009f2bb25e8ac9bced2/oauth2_provider/models.py#L78) > > Our model for reproduction: > > {{{ > class RefreshToken(models.Model): > user = models.ForeignKey( > settings.AUTH_USER_MODEL, on_delete=models.CASCADE, > related_name="%(app_label)s_%(class)s" > ) > > }}} > > Users of the package are running `makemigrations` and having to see > something like this (ref: https://github.com/jazzband/django-oauth- > toolkit/issues/1037): > > {{{ > migrations.AlterField( > model_name='refreshtoken', > name='user', > field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, > related_name='%(app_label)s_%(class)s', to='auth.user'), > ), > }}} > > Specifically, `to='auth.user'` is the issue. Our previous migrations > properly had `to=settings.AUTH_USER_MODEL`. Please let me know how to fix > this or whether this is a bug. Thanks! New description: We have a model in a package called [django-oauth- toolkit](https://github.com/jazzband/django-oauth- toolkit/blob/0204383f7b6f8739322f2009f2bb25e8ac9bced2/oauth2_provider/models.py#L78) Our model for reproduction: {{{ class RefreshToken(models.Model): user = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="%(app_label)s_%(class)s" ) }}} Users of the package are running `makemigrations` and having to see something like this (ref: https://github.com/jazzband/django-oauth- toolkit/issues/1037): {{{ migrations.AlterField( model_name='refreshtoken', name='user', field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(app_label)s_%(class)s', to='auth.user'), ), }}} Specifically, `to='auth.user'` is the issue. Our previous migrations properly had `to=settings.AUTH_USER_MODEL`. Please let me know how to fix this or whether this is a bug. As noted in that linked issue, it might be due to https://docs.djangoproject.com/en/4.0/releases/4.0/#migrations- autodetector-changes, and if this functionality is intended, then how can packages... avoid this? Thanks! -- -- Ticket URL: <https://code.djangoproject.com/ticket/33366#comment:2> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/074.e8e17220d01729540639593ea0cef328%40djangoproject.com.