3

Every time I wipe the database of my Django app during testing (or when cloning or deployin), I have to go into /admin and set up permissions and groups. Where would I put the code that would populate the DB with them and what would it look like?

ekad
  • 14,436
  • 26
  • 44
  • 46
StokedOver9k
  • 129
  • 1
  • 9
  • You are creating database each time you make a change? I think that better solution would be to use `south` to migrate DB. – Silwest Mar 17 '14 at 15:10

2 Answers2

4

For this you can use fixtures.

For example:

python manage.py dumpdata auth > fixtures/auth.json

This will store all models of package 'auth' (Users, Groups Relations) into auth.json After Deployment you can use the following command to load:

python manage.py loaddata auth fixtures/auth.json

This will restore your prev state of 'auth'.

Maybe it's good for you to switch to South, a very famous part of Django to migrate databases instead of recreating them.

mrcrgl
  • 640
  • 4
  • 11
  • Thanks! And you're right, I probably should just switch to the _right_ way of doing things... but sometimes the quick and dirty fix is just too easy to forego. – StokedOver9k Mar 17 '14 at 16:09
0

You can provide fixtures with the initial required data and it will be automatically inserted when you syncdb. See docs

almalki
  • 4,595
  • 26
  • 30