Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

null value in column "last_login" violates not-null constraint

Having issues getting rid of this error.

I'm trying to use Digital Ocean to deploy my Django app. I configured Postgres, but when I'm trying to register a new user in my app, I get this problem.

I've tried running python manage.py makemigrations and python manage.py migrate and they work fine. The SQL migrations are completed upon migration.

like image 224
noobprogrammer Avatar asked Nov 12 '15 23:11

noobprogrammer


2 Answers

Try add this to your imports:

from django.utils import timezone

Then wherever you grab the user's data to save the new user add before the save procedure:

<user_object>.last_login = timezone.now() 
like image 200
Richard Kenneth Niescior Avatar answered Oct 20 '22 18:10

Richard Kenneth Niescior


I was upgrading from django 1.7 to django 1.10 when I ran into this. What it ended up being was I needed to run python manage.py migrate to update the database tables and columns.

like image 42
teewuane Avatar answered Oct 20 '22 20:10

teewuane