Django ValueError when running "python manage.py migrate" command

I needed to add more fields to the User Django model , so I created a special model class (named Accounts ) in an application named accounts ) that extends the Django AbstractUser class .

After that, I updated the settings.py file with the AUTH_USER_MODEL property :

AUTH_USER_MODEL = 'accounts.Accounts'

Then I created a migration file for the user model using the command python manage.py makemigrations.

After that, I ran the command python manage.py migrateand I received this error message:

ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'accounts.accounts', but app 'accounts' isn't installed.

What is the cause of the error and how to fix it?

UPDATE: Now, if I run the command python manage.py makemigrations, I get this error message:

ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'accounts.accounts', but app 'accounts' doesn't provide model 'accounts'.
+8
source share
6 answers

You just delete your previous 0001_initial.py in the migration folder and try to perform makemigration and reconfigure again

+10
source

This is simply because you already have an example user model by default, I think. Start a new project and reconfigure your models again, and it should work.

+2
source

accounts INSTALLED_APPS. accounts.apps.AccountsConfig . accounts INSTALLED_APPS

+1

, , , , "Your-project-env/lib/python3". 5/-////".

+1

. . , ( pycache, 0001.intial .., init.py) YouProject\lib\site-packages\django\contrib\admin\migrations

0

I have the same problem. look under your class in models.py, change app_labelto the name of your application, I put the class name, and then an error came. By doing this, I think it fixes the errors.

class Meta:
        app_label = 'put_app_name'

Sorry for some grammatical error, I am using Google translator.

0
source

Source: https://habr.com/ru/post/1658714/


All Articles