return Database.Cursor.execute(self, query, params) django.db.utils.IntegrityError: NOT NULL constraint failed: auth_user.last_login when adding a superuser

1,854 views
Skip to first unread message

Adam

unread,
Feb 12, 2017, 7:12:07 AM2/12/17
to Django users
Hi everyone, 

I'm super new to django, I tried to add a superuser and this is the error I got: 


File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 323, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.IntegrityError: NOT NULL constraint failed: auth_user.last_login


I tried to run migrate and did also migrate --fake but it did not resolve the issue, any clues what could be my issue ?

Cheers everyone,

Antonis Christofides

unread,
Feb 12, 2017, 7:19:16 AM2/12/17
to django...@googlegroups.com

Hello, please show the full traceback.

Antonis Christofides
http://djangodeployment.com
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/96c76c04-6277-446e-8488-90ba22fa548a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adam

unread,
Feb 12, 2017, 1:33:09 PM2/12/17
to Django users
Hi Antonis, this is the full message including the command:

:~/udemystuff/test_project# python manage.py createsuperuser
/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/template/utils.py:37: RemovedInDjango110Warning: You haven't defined a TEMPLATES setting. You must do so before upgrading to Django 1.10. Otherwise Django will be unable to load templates.
  "unable to load templates.", RemovedInDjango110Warning)

/root/udemystuff/test_project/test_project/urls.py:11: RemovedInDjango110Warning: django.conf.urls.patterns() is deprecated and will be removed in Django 1.10. Update your urlpatterns to be a list of django.conf.urls.url() instances instead.
  url(r'^admin/', include(admin.site.urls)),

Username (leave blank to use 'root'): adams
Email address:
Password:
Password (again):
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 342, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 52, in execute
    return super(Command, self).execute(*args, **options)
  File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 173, in handle
    self.UserModel._default_manager.db_manager(database).create_superuser(**user_data)
  File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/contrib/auth/models.py", line 165, in create_superuser
    return self._create_user(username, email, password, **extra_fields)
  File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/contrib/auth/models.py", line 148, in _create_user
    user.save(using=self._db)
  File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 74, in save
    super(AbstractBaseUser, self).save(*args, **kwargs)
  File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/db/models/base.py", line 700, in save
    force_update=force_update, update_fields=update_fields)
  File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/db/models/base.py", line 728, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/db/models/base.py", line 812, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/db/models/base.py", line 851, in _do_insert
    using=using, raw=raw)
  File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/db/models/manager.py", line 122, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/db/models/query.py", line 1039, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 1064, in execute_sql
    cursor.execute(sql, params)
  File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/root/udemystuff/test_project/trydjango19/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)

ludovic coues

unread,
Feb 13, 2017, 4:48:34 AM2/13/17
to django...@googlegroups.com
Have you tried to run makemigrations before migrate ?

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Tim Graham

unread,
Feb 13, 2017, 7:19:41 AM2/13/17
to Django users
It looks like you're missing a migration to allow null values in the last_login column. If you ran "migrate --fake", then it's possible some migrations were "fake applied" and you'll need to "fake unapply" them and actually run them.

https://docs.djangoproject.com/en/stable/releases/1.8/#abstractuser-last-login-allows-null-values
Reply all
Reply to author
Forward
0 new messages