Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

its my installed apps :

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'
]

and i used user in models :

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'))

migration now is 0013

when i use backward migrate like this :

migrate Blog 0011

error happend :

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

also i do not have AUTH_USER_MODEL in settings.py

also i can not remove data base because have so many data on it.

what is problem??

using django2.2 python3.7 postgresql

like image 627
motad333 Avatar asked Oct 15 '25 15:10

motad333


1 Answers

the problem was in migrations dependencies

no where imported auth

so i add below code in some of the first Blog migrations and error solved

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

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

actually if you see this error on other your_app just add some of migrations of your_app to dependencies like as below:

dependencies = [
        ('accounts', '0012_auto_20200730_1818'),
        ...
    ]
like image 86
motad333 Avatar answered Oct 17 '25 06:10

motad333