简体   繁体   English

Django + django-oauth-toolkit 上的迁移错误

[英]Migration error on Django + django-oauth-toolkit

I have an django application with version 2.2.13 and django oauth toolkit 1.0.0.我有一个 django 应用程序,版本为 2.2.13 和 django oauth 工具包 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).为了更新到 Django 3.0,我需要更新 django-oauth-toolkit,但是在 1.0.0 版之后的每个版本,我都遇到了迁移问题,因为我的应用程序 (oauth2) 扩展了抽象应用程序 (AbstractApplication) Z20F35E630DAF44DBFA4C3F68F5399D8 oauth2_provider(来自 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.这个自定义 oauth 应用程序 (oauth2) 有 28 个迁移,这些迁移是在项目本身内部生成的。

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当我们尝试从头开始运行所有迁移时(我们在 CI 服务器上执行此操作),尝试为应用程序oauth2_provider运行迁移 0001 时出现错误

ValueError: Related model 'oauth2.Application' cannot be resolved . 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.有一个类似于我在项目中打开的问题https://github.com/jazzband/django-oauth-toolkit/issues/778的问题,但提供的解决方法不起作用,我还没有找到其他解决方案。

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.当您交换应用程序 model 时,您应该在设置 OAUTH2_PROVIDER_APPLICATION_MODEL 之前创建并运行定义交换应用程序 model 的迁移。

It is possible to force your migration providing the custom model to run in the right order by adding:通过添加以下内容,可以强制您的迁移提供自定义 model 以正确的顺序运行:

run_before = [
    ('oauth2_provider', '0001_initial'),
]

to the migration class.迁移到 class。

You can find more details here您可以在此处找到更多详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM