Open smit-mehta25 opened 2 years ago
@smit-mehta25 I assume your comment means this is a dup of #634?
@smit-mehta25 same problem, i update to django 4.0.2 solved.
similar issue when I run migration: ./manage.py migrate xxxx zero
my django version is 4.0.5:
ValueError: The field oauth2_provider.AccessToken.application was declared with a lazy reference to 'ucenter.application', but app 'ucenter' doesn't provide model 'application'.
The field oauth2_provider.Grant.application was declared with a lazy reference to 'ucenter.application', but app 'ucenter' doesn't provide model 'application'.
The field oauth2_provider.IDToken.application was declared with a lazy reference to 'ucenter.application', but app 'ucenter' doesn't provide model 'application'.
The field oauth2_provider.RefreshToken.application was declared with a lazy reference to 'ucenter.application', but app 'ucenter' doesn't provide model 'application'.
@phith0n Can you be specific about what versions you are using? The issue was created back several months ago and also didn't reference the version. Please fill out this template:
Describe the bug
To Reproduce
Expected behavior
Version
Additional context
Also, I would ask that you repeat your reproducing test with Django 3.2 and with DOT 1.7.1 to help isolate if this is due to a change in Django or in DOT 2.x.
Thanks.
Hi @n2ygk , I think I may have found the problem.
Refer to the document https://django-oauth-toolkit.readthedocs.io/en/latest/advanced_topics.html#AbstractApplication, everything is OK after I added run_before = [('oauth2_provider', '0001_initial'),]
to the migrations that created ucenter.Application
.
However, the error models.E022
stated in the documentation was not thrown.
I believe this run_before
requirement is a symptom of the migrations not listing all the required dependencies on swappable models. In the initial migration, I suspect this in 0001_initial:
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL)
]
should be changed to this to make sure all possible swappable models become dependencies:
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
migrations.swappable_dependency(settings.APPLICATION_MODEL),
migrations.swappable_dependency(settings.ACCESS_TOKEN_MODEL),
migrations.swappable_dependency(settings.ID_TOKEN_MODEL),
migrations.swappable_dependency(settings.GRANT_MODEL),
migrations.swappable_dependency(settings.REFRESH_TOKEN_MODEL),
]
This has to do with auto-generated migrations (manage.py makemigrations
) assuming the only possible swappable model is the User model as that's the "usual" case in other parts of Django.
I haven't had time to test this. Swappable models have been an ongoing point of confusion with this library forever.
See also #871, #778, #634 and https://github.com/openwisp/django-swappable-models (which I don't quite understand the point of).
I am constantly facing this issues. Is there any solutions for this one,
oauth2_provider setting configurations:
Even, I tried to apply
run_before
to my custom initial migrations. But No luck.This is with
Django==3.2.11
anddjango-oauth-toolkit==1.7.0
Below is the order of Apply migrations.
But still i am facing the above error. I have tried everything that i could from other open issues. Such as ... Swappable models. Clean migrations, run before.