1

I'm trying to have a purely in-memory SQLite database in Django, and I think I have it working, except for an annoying problem:

I need to run syncdb before using the database, which isn't too much of a problem. The problem is that it needs to create a superuser (in the auth_user table, I think) which requires interactive input.

For my purposes, I don't want this -- I just want to create it in memory, and I really don't care about the password because I'm the only user. :) I just want to hard-code a password somewhere, but I have no idea how to do this programmatically.

Any ideas?

3 Answers 3

6

Any inputs or prompts of django-admin.py may be suppressed using the --noinput option, such as

./manage.py syncdb --noinput

This will skip the super user creation on the initial syncdb run and thus requires you to create one either using fixtures or an custom method as receiver of the post_syncdb signal.

See django-admin.py and manage.py in the Django docs:

--noinput

Use the --noinput option to suppress all user prompting, such as "Are you sure?" confirmation messages. This is useful if django-admin.py is being executed as an unattended, automated script.

Sign up to request clarification or add additional context in comments.

Comments

3

Disconnect django.contrib.auth.management.create_superuser from the post_syncdb signal, and instead connect your own function that creates and saves a new superuser User with the desired password.

Comments

1

You will want to use fixtures:

https://docs.djangoproject.com/en/1.3/howto/initial-data/

2 Comments

Thanks for the link. I'm unfortunately not quite sure how to use them, though -- how would they be able to create a password for Django itself?
Once you have a running copy with the user you want simply export a fixture from the users model. ./manage.py dumpdata auth.User > initial_data.json. This fixture will be loaded every time you run syncdb docs.djangoproject.com/en/1.3/howto/initial-data/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.