add-semi-colons
add-semi-colons

Reputation: 18810

django south migration: Reset the schema only few tables

I am new django south migration. I have my main application and most of additional functions of that application I built as sub applications of the main application. Now what I want to do is reset the tables that are specific to sub application of the main application. I don't want to loose any data from other tables table.

This is how my database look like:

 public | tos_agreement                       | table | g_db_admin
 public | tos_agreementversion                | table | g_db_admin
 public | tos_signature                       | table | g_db_admin
 public | userclickstream_click               | table | g_db_admin
 public | userclickstream_stream              | table | g_db_admin
 public | vote                                | table | g_db_admin
(80 rows)

I only want to re-build (dump all data of)
public | userclickstream_click | table | g_db_admin public | userclickstream_stream | table | g_db_admin

How can I do this using south migration.

In my south_migrationhistory table I have following:

  15 | userclickstream   | 0001_initial                                                                | 2013-12-10 13:26:15.684678-06
  16 | userclickstream   | 0002_auto__del_field_stream_auth_user                                       | 2013-12-10 13:26:15.693485-06
  17 | userclickstream   | 0003_auto__del_field_stream_username__add_field_stream_user                 | 2013-12-10 13:26:15.721449-06

I assume this record took place when I initially wired up it with south migration.

I was also thinking what if? Delete the above records from south_migrationhistory and re-run the migration for this app which will generate the tables.

./manage.py schemamigration userclickstream --initial
./manage.py migrate userclickstream

Upvotes: 0

Views: 77

Answers (1)

yuvi
yuvi

Reputation: 18427

Do it this way:

  1. Open up your terminal and write manage.py dumpdata > backup.json. it will create a json fixture with all data currently in the database. That way, if you screw up anything, you can always re-load the data with manage.py loaddata backup.json (note that all tables need to be empty for this to work).
  2. optional: pass the data to a new development db using the aformentioned loaddata command
  3. Write your own migration, and not worry about breaking anything because - hey, you got a backup. It might take some learning, but the basic idea is you create a migration class with two functions - forward and reverse. Check out the south documentation and pick it up slowly from there.
  4. Come back to SO with any more specific question and troubles you have along the way

This isn't a coded "here's the solution" answer, but I hope this helps nonetheless

Upvotes: 1

Related Questions