Holy crap, that's useful. I never thought of that.. jeez.
Aidas Bendoraitis
· 1 year ago
I am also using the same technique for developing and testing one of my projects. But rather I dump all data from all tables into a fixture.
Metin
· 1 year ago
Incredible! Thanks for sharing. Until there's some sort of "usable" migrations for Django, I'm gonna stick with this method of local development.
Jean-Philippe Bougie
· 1 year ago
I think a better technique would be to use the ./manage.py reset [app] command, which will only destroy the data of the apps you're developing, and not of the contrib stuff. As long as you don't touch the user data model, it should be a simpler solution. ./manage sqlreset [app] can be used to check what will be executed prior to doing it
Martin
· 1 year ago
Really nice. Until now I always used "raw sql" fixtures, without the session thing. Will use this from now on. :)
D3f0
· 1 year ago
I've made a script that instead of syncdb. Basically it does the same thing.
os.system('rm -rf db/*') # remove Sqlite files, we store SQlite dbs in ./db os.system('python manage.py syncdb --noinput') os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' from django.contrib.auth.create_superuser import createsuperuser createsuperuser(**SUPERUSER_DATA)
Jiri Barton
· 1 year ago
A brilliant idea it is. Let me extend it a bit further. Create an empty application "superuser" and put your dump there. Include this application in your settings:
I've been using this technique since you posted it - thanks! Unfortunately, I now want to have initial SQL data loaded into some of my other tables which is keyed off the user - and the initial_data.json fixture is loaded right at the end, after the initial SQL data for the other tables. Can you think of a solution that will still continue to work in this situation?
import os
import sys
sys.path.append('..')
SUPERUSER_DATA = {
'username':'admin',
'email':'admin@admin.com',
'password': 'admin'
}
os.system('rm -rf db/*') # remove Sqlite files, we store SQlite dbs in ./db
os.system('python manage.py syncdb --noinput')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from django.contrib.auth.create_superuser import createsuperuser
createsuperuser(**SUPERUSER_DATA)
<pre>
mkdir -p superuser/fixtures
touch superuser/__init__.py superuser/models.py
./manage dumpdata auth >superuser/fixtures/initial_data.json
<pre>
Add 'superuser' to the list of your INSTALLED_APPS in your settings.py. syncdb --noinput will install the fixture automatically.
http://lurkingideas.net/blog/2008/sep/18/creati...
Sorry for littering your blog.