First time here? Check out the FAQ!

spascoe's profile - activity

2014-04-13 13:56:58 -0500 received badge Scholar ( source )
2014-04-10 06:24:51 -0500 asked a question IntegrityError during scripted creation of superuser

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

from django.core.management import setup_environ
import settings
setup_environ(settings)

from django.contrib.auth.models import User

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

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

Traceback (most recent call last):
  File "mkadmin.py", line 12, in <module>
    u.save()
  File "/var/www/askbot/lib/python2.6/site-packages/django/db/models/base.py", 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/base.py", 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?

2014-02-10 10:37:41 -0500 answered a question NameError: global name 'User' is not defined (Fresh install) (askbot only)

My diagnosis is that the module django.contrib.auth.management.commands.createsuperuser no longer exports the User model. The module askbot.management.commands.createsuperuser expects this in the code.

If you remove the askbot.management.commands.createsuperuser module you can use the default Django createsuperuser command. It seems to work provided you initially answer "no" when running syncdb and run createsuperuser separately after migrating.