Search code examples
pythonmysqldjangodjango-southinsertion

Can the South (for Django) insert rows of data into database?


I want to create a table, and then a list of data that should be inserted into that table. Does South have the capability to do such a thing? If so, do you have any reference as to show me how this can be done?

I want to be able to do this because at this point, it seems like the only way to have the 'exact' same data is to manually insert them into the database ourselves.

I want some 'nice' automated way of inserting rows in a table.


Solution

  • You'd want to use fixtures.

    1. Create a fixtures directory in your app's folder.
    2. Create a dictionary file in that folder, intial_data.json (or XML/YAML)
    3. Populate the file with the data you'd want to insert. Example
    4. Run manage.py loaddata <fixturename>, where <fixturename> is the name of the fixture file you've created.

    South handles this pretty much the same way, but it seems like Django's core approach is more documented.