Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating users in django (NOT NULL constraint failed: auth_user.last_login)

I'm coding a web app with django and now I'm starting to handle users. I'm trying to do the easy part, just create a new user throught admin interface, but when I try to do it I get a error and I don't find any info about it.

I enter django admin, log in with superuser, go to users, add user. It only asks for: username and password. When I submit changes then I get a NOT NULL constraint failed, this:

NOT NULL constraint failed: auth_user.last_login

I revised django documentation, and there it says to create a user like this:

  • from django.contrib.auth.models import User
  • user = User.objects.create_user('john', '[email protected]', 'johnpassword')

So, I open a terminal, and do "./manage.py shell" "import django" "import User" and then I try this code, but fails too, it says:

NameError: name 'User' is not defined

Maybe I've changed something in the first part of the project? I've created models, templates, urls and used /static/ for references to files.

Thanks for your help!

like image 303
rul3s Avatar asked May 31 '15 10:05

rul3s


2 Answers

last_login field changed in django 1.8. Just run the migrations

python manage.py migrate
like image 158
kmmbvnr Avatar answered Nov 20 '22 07:11

kmmbvnr


Same issue, Had to run python manage.py migrate --fake and then python manage.py migrate and it worked perfectly.

like image 3
Stryker Avatar answered Nov 20 '22 07:11

Stryker