fixtures.rst 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. Fixtures
  2. ========
  3. A few things change when you're using fixtures with South.
  4. initial_data
  5. ------------
  6. Much like syncdb, South will load the initial_data fixture when an app has been
  7. successfully migrated to the latest migration for an app. Note that the data in
  8. the fixture will not be available before then; South only applies it at the end,
  9. as it may not match the current database schema.
  10. Fixtures from migrations
  11. ------------------------
  12. If you need to load a fixture as part of your database setup - say, you have a
  13. migration that depends on it being around - the best thing to do is to write a
  14. new migration to load the fixture in. That way, the fixture will always be
  15. loaded at the correct time.
  16. To make such a migration, first make a blank migration::
  17. ./manage.py startmigration appname load_myfixture
  18. Then, open the new migration file, and restructure your forwards() method
  19. so it looks like this::
  20. def forwards(self, orm):
  21. from django.core.management import call_command
  22. call_command("loaddata", "my_fixture.json")
  23. (you'll have to leave backwards() empty,
  24. as there's no much you can do to reverse this).
  25. Then, when this migration is run, it will load the given fixture.