I'm using Django 2.x
and OAuth Toolkit
.
I'm writing an application where I need to add ForeignKey
pointing to Application
model of OAuth Toolkit
plugin, which is defined Abstract.
According to the documentation. I can extend the AbstractApplication and then add in settings
OAUTH2_PROVIDER_APPLICATION_MODEL='your_app_name.MyApplication'
In my case, I have created my app and in models.py
class CustomOAuthToolkitApplication(AbstractApplication):
pass
class OAuthToolkitTrackingLog(models.Model):
application_model = settings.OAUTH2_PROVIDER_APPLICATION_MODEL
application = models.ForeignKey(application_model, on_delete=models.CASCADE, blank=True, default=None, null=True)
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True, default=None)
col_1 = models.CharField(max_length=255)
created = models.DateTimeField(auto_now_add=True)
and in settings.py
INSTALLED_APPS = [
...
'oauth2_provider',
'my_app',
]
OAUTH2_PROVIDER_APPLICATION_MODEL = 'my_app.CustomOAuthToolkitApplication'
But when I run command to generate migration
python manage.py makemigrations
It gives error as
The field oauth2_provider.Grant.application was declared with a lazy reference to 'my_app.customoauthtoolkitapplication', but app 'my_app' isn't installed.
The field oauth2_provider.RefreshToken.application was declared with a lazy reference to 'my_app.customoauthtoolkitapplication', but app 'my_app' isn't installed.
How can I fix this issue?
Hmmm. I'm not sure. But as far as I remember from django source code, the order in INSTALLED_APPS matters. Could you please try switching places, so:
So that my_app is higher on the list?