0

我正在使用Django 2.xOAuth Toolkit

我正在编写一个应用程序,我需要在其中添加ForeignKey指向插件Application模型的指针OAuth Toolkit,该模型定义为Abstract

根据文档。我可以扩展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.

我该如何解决这个问题?

4

1 回答 1

0

嗯。我不确定。但据我记得 django 源代码,INSTALLED_APPS 中的顺序很重要。你能不能换个地方试试,所以:

INSTALLED_APPS = [
  ...
  'my_app',
  'oauth2_provider',
]

所以 my_app 在列表中更高?

于 2018-11-22T18:53:32.760 回答