Sql source data does not start for applications managed by the South. From what I understood, this is by design, although I could not find any formal evidence of this other than this mailing list .
To achieve the same behavior, you can create a wrapper and convert your SQL to Python. So I did this to set the view:
Create and edit hyphenation:
$ python manage.py schemamigration app1 install_foo_view --empty $ vim app1/migrations/*_install_foo_view.py
Here the migration itself:
from south.db import db from south.v2 import SchemaMigration class Migration(SchemaMigration): def forwards(self, orm): db.execute("CREATE VIEW app1_foo AS SELECT col1, col2 FROM app1_bar") def backwards(self, orm): db.execute("DROP VIEW app1_foo")
To transfer data, the stream looks like:
$ python manage.py datamigration app1 install_bars $ vim app1/migrations/*_install_bars.py
Here the migration itself:
from south.db import db from south.v2 import DataMigration class Migration(DataMigration): def forwards(self, orm): orm.Bar.objects.create(col1='val1', col2='val2') def backwards(self, orm): orm.Bar.objects.filter(col1='val1', col2='val2').delete()
The default white paper for data is violated:
It does not scale well with respect to circuit changes.
You must copy and customize the instrument file each time you change the fields of the Bar model. So you get "my_fixture_v1.json", "my_fixture_v2.json", etc.
Otherwise, if you do not save their version and do not save the latest version, there will be discrepancies between previous versions of the model and the device, and you will not be able to navigate the transitions back and forth.
- It does not support reverse migration.
The proposed approach takes care of all these problems:
- Since you use
orm.Bar , you have a set of fields that apply to Bar right at this point in history. You will not receive any missing or additional fields. - No need to copy anything with
Bar changes. You can jump back.
Note that instead of get().delete() , the combination filter().delete() . Thus, you will not delete the Bar that was changed by the user, and you did not work with Bar.DoesNotExist when you did not find them.
Ihor kaharlichenko
source share