Opened 3 years ago
Last modified 3 years ago
#33366 closed Bug
Foreign key to settings.AUTH_USER_MODEL causes hard-coded alteration in migration — at Initial Version
Reported by: | Andrew Chen Wang | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 4.0 |
Severity: | Release blocker | Keywords: | |
Cc: | Keryn Knight, David Wobrock, Simon Charette | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
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!