我正在使用Django 2.x
和OAuth Toolkit
。
我正在编写一个应用程序,我需要添加指向ForeignKey
插件的Application
模型的OAuth Toolkit
,该模型定义为 Abstract 。
根据the documentation。我可以扩展 AbstractApplication ,然后添加设置
OAUTH2_PROVIDER_APPLICATION_MODEL='your_app_name.MyApplication'
就我而言,我已经在 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)
和 settings.py
中INSTALLED_APPS = [
...
'oauth2_provider',
'my_app',
]
OAUTH2_PROVIDER_APPLICATION_MODEL = 'my_app.CustomOAuthToolkitApplication'
但是当我运行命令来生成迁移
python manage.py makemigrations
它给出错误为
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.
如何解决此问题?
答案 0 :(得分:0)
嗯。我不确定。但是据我从Django源代码记得的那样,INSTALLED_APPS中的顺序很重要。您能否尝试切换位置,所以:
INSTALLED_APPS = [
...
'my_app',
'oauth2_provider',
]
以便my_app在列表上更高?