Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I needed to add more fields to Django's User model, so I created a custom model class (named Accounts in an app named accounts) that extends Django's AbstractUser class.

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

AUTH_USER_MODEL = 'accounts.Accounts'

I then created a migration file for the custom model using the python manage.py makemigrations command.

After that, I ran the python manage.py migrate command and I got 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's the cause of the error and how can I fix it?

UPDATE: Now, if i run the python manage.py makemigrations command, 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'.
like image 575
Inyavic Sage Avatar asked Oct 24 '16 15:10

Inyavic Sage


People also ask

What does Django manage py migrate do?

migrate executes those SQL commands in the database file. So after executing migrate all the tables of your installed apps are created in your database file.

What is migration command in Django?

Migrations are Django's way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema. They're designed to be mostly automatic, but you'll need to know when to make migrations, when to run them, and the common problems you might run into.


3 Answers

You just delete your previous 0001_initial.py in the migrations folder and try doing the makemigration and migrate again

like image 131
Chandramouli Rajagopalan Avatar answered Oct 11 '22 20:10

Chandramouli Rajagopalan


I have the similar problem. It is the admin app has the cache and migrations history. I solve it by deleting all the cache and migrations history record(pycache file, and 0001.intial etc., keep init.py only) in YouProject\lib\site-packages\django\contrib\admin\migrations

like image 45
Henning Lee Avatar answered Oct 11 '22 18:10

Henning Lee


I too had a similar problem when I changed the name of one of my apps, I had to delete migrations files at two locations, all migrations for the specific app migration folder, then migrations at "Your-project-env/lib/python3.5/site-packages/django/contrib/admin/migrations".

like image 20
Aldo Okware Avatar answered Oct 11 '22 18:10

Aldo Okware