该字段是使用对 'auth.user' 的惰性引用声明的,但未安装应用程序 'auth'

The field was declared with a lazy reference to 'auth.user', but app 'auth' isn't installed

这是我安装的应用程序:

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'leadgenerator',
'leadgenerator.apps.ui',
'leadgenerator.apps.accounts',
'leadgenerator.apps.instagram',
'leadgenerator.apps.BorseBots',
'leadgenerator.apps.TelegramBorse',
'leadgenerator.apps.Utils',
'leadgenerator.apps.Blog',
'leadgenerator.apps.Crypto',
'channels',
'multiselectfield',
'django_redis',
'django_filters',
'extra_views',
'django_select2',
'compressor',
'django_celery_beat',
'crispy_forms',
'django_tables2',
'ckeditor',
'ckeditor_uploader',
# 'leadgenerator.ckeditor5',
'leadgenerator.rolepermissions',
'rolepermissions',

# login and login_as
'loginas',
'allauth',
'allauth.account',
'allauth.socialaccount',
'phonenumber_field',

# blog
'modelcluster',
'taggit',
# end blog
'imagekit',
'pwa'
]

我在模型中使用了用户:

from django.contrib.auth.models import User as djangoUser
class BlogPost(models.Model):
    author = models.ForeignKey(djangoUser, on_delete=models.CASCADE, related_name='blog_posts', verbose_name=_('Author'))

迁移现在是 0013

当我像这样使用向后迁移时:

migrate Blog 0011

发生错误:

ValueError: The field Blog.BlogPost.author was declared with a lazy reference to 'auth.user', but app 'auth' isn't installed.

而且我在settings.py

中没有AUTH_USER_MODEL

我也无法删除数据库,因为上面有太多数据。

有什么问题??

使用 django2.2 python3.7 postgresql

问题出在迁移依赖项中

没有导入授权的地方

所以我在第一个 Blog migrations 中添加了下面的代码并解决了错误

Blog/migrations/0003....py # file name

dependencies = [
    migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ...
]

实际上,如果您在其他 your_app 上看到此错误,只需将 your_app 的一些迁移添加到依赖项中,如下所示:

dependencies = [
        ('accounts', '0012_auto_20200730_1818'),
        ...
    ]