我使用的是Django 2.x
和OAuth Toolkit
。
我正在编写一个应用程序,需要添加指向OAuth Toolkit
插件的Application
模型的ForeignKey
,该模型定义为抽象。
根据文件。我可以扩展抽象应用程序,然后添加设置
OAUTH2_PROVIDER_APPLICATION_MODEL='your_app_name.MyApplication'
在我的案例中,我已经创建了我的应用程序和模型。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)
以及在设置中。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.
如何解决此问题
嗯。我不确定。但据我记忆中的django源代码,INSTALLED_APPS中的顺序很重要。你能试着换个地方吗?所以:
INSTALLED_APPS = [
...
'my_app',
'oauth2_provider',
]
所以my_app在列表中的位置更高?