I have an django application with version 2.2.13 and django oauth toolkit 1.0.0. In the effort to update to Django 3.0, I need to update the django-oauth-toolkit, but every version after version 1.0.0, I run into a migration problem because my application (oauth2) extends the abstract application (AbstractApplication) model from the oauth2_provider (from django-oauth-toolkit).
from oauth2_provider.models import AbstractApplication
class Application(AbstractApplication):
# there are more fields added here
pass
This custom oauth application (oauth2) has 28 migrations that were generate inside the project itself.
When we try to run all migrations from scratch (we do this on our CI Server), we get an error trying to run migration 0001 for the app oauth2_provider
ValueError: Related model 'oauth2.Application' cannot be resolved
.
There is an issue similar to my problem open on the project, https://github.com/jazzband/django-oauth-toolkit/issues/778, but workaround provided does not work, and I have not found other solution to it.
Thanks.
when you swap the application model, you should create and run the migration defining the swapped application model prior to setting OAUTH2_PROVIDER_APPLICATION_MODEL.
It is possible to force your migration providing the custom model to run in the right order by adding:
run_before = [
('oauth2_provider', '0001_initial'),
]
to the migration class.
You can find more details here