Ask Your Question

IntegrityError during scripted creation of superuser

asked 2014-04-10 06:24:51 -0500

spascoe's avatar

I am trying to create a superuser automatically with the following code:

from import setup_environ
import settings

from django.contrib.auth.models import User

u = User(username='<USER>')
u.is_superuser = True
u.is_staff = True

However, I get this IntegrityError which I believe is connected to addition of the User.status field:

Traceback (most recent call last):
  File "", line 12, in <module>
  File "/var/www/askbot/lib/python2.6/site-packages/django/db/models/", line 546, in save
    force_update=force_update, update_fields=update_fields)
  File "/var/www/askbot/lib/python2.6/site-packages/django/db/backends/postgresql_psycopg2/", line 54, in execute
    return self.cursor.execute(query, args)
django.db.utils.IntegrityError: null value in column "status" violates not-null constraint

I've tried adding u.status="a" but this doesn't help. The database query still doesn't include the status column. Any ideas how this can be done?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-04-12 12:17:32 -0500

Evgeny's avatar

Change from django.contrib.auth.models import User to from askbot.models import User

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-04-10 06:24:51 -0500

Seen: 353 times

Last updated: Apr 12 '14