Django In-Memory SQLite3 Database
I'm trying to have开发者_JS百科 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?
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.
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.
You will want to use fixtures:
https://docs.djangoproject.com/en/1.3/howto/initial-data/
精彩评论