Search code examples
djangodjango-southdata-migration

Possible to migrate bool to int, converting values


I'm vaguely familiar with the concept of migrating schemes and data with South, but now i'd like accomplish something a bit more advanced;

I have a model which holds a boolfield indicating status (active/not active), and now I need to add additional possibilities using an integerfield. The change itself is pretty straightforward using Souths schememigration.

Problem is I need to convert the statuses in the existing objects (some 400+) to integers (0 for false and 1 for true).

Is this even possible, or do I need to find another way?


Solution

  • This was pretty straight-forward after reading the docs (doh!).

    schemamigration - add intfield datamigration - if bool >> int = 1, else int = 0 schemamigration - remove boolfield