I hope I've distilled this down to a simple enough example to tell whether I'm doing something wrong or I've uncovered a bug. I am using Django 1.6.6 and South 0.8.4 or 1.0 (tried both).
My model is as follows for the migration below:
class Zone(models.Model):
name = models.CharField('Zone Name', max_length=1024)
geo = models.PolygonField('Geo Data about Zone')
objects = models.GeoManager()My migration is as follows:
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'Zone.geo'
db.add_column(u'mapping_zone', 'geo',
self.gf('django.contrib.gis.db.models.fields.PolygonField')(null=True),
keep_default=False)If I run this migration as:
./manage.py migrate -v 3 mapping I get the following output:
> mapping:0002_auto__chg_field_zone_geo
= SELECT AddGeometryColumn('mapping_zone', 'geo', 4326, 'POLYGON', 2, 0); []
= SELECT CreateSpatialIndex('mapping_zone', 'geo'); []
= CREATE TABLE "_south_new_mapping_zone" ("geo" None, "map_id" integer NOT NULL, "name" varchar(1024) NOT NULL) []
= INSERT INTO "_south_new_mapping_zone" ("name", "map_id") SELECT "name", "map_id", FROM "mapping_zone"; []
= DROP TABLE "mapping_zone"; []
= ALTER TABLE "_south_new_mapping_zone" RENAME TO "mapping_zone"; [] = CREATE INDEX "mapping_zone_51513134" ON "mapping_zone"("map_id"); []The result is the new mapping_zone table is created incorrectly and doesn't have the field type set correctly and all the Spatialite fields are missing. It appears that I need to suppress the CREATE TABLE from occurring. The hack to make this happens appears to be to edit
south/db/sqlite3.py in the
add_column() method, the last line is a call to
self._remake_table() which needs to be changed as follows:
if field.__class__.__module__ == 'django.contrib.gis.db.models.fields':
self._column_sql_for_create(table_name, name, field, False)
else:
self._remake_table(table_name, added={
field.column: (self._column_sql_for_create(table_name, name, field, False), field_default)
})Now if I delete my database and start over and migrate again I get the following behavior:
> mapping:0002_auto__chg_field_zone_geo
= SELECT AddGeometryColumn('mapping_zone', 'geo', 4326, 'POLYGON', 2, 0); []
= SELECT CreateSpatialIndex('mapping_zone', 'geo'); []
= SELECT AddGeometryColumn('mapping_zone', 'geo', 4326, 'POLYGON', 2, 0); []
= SELECT CreateSpatialIndex('mapping_zone', 'geo'); []The double call doesn't seem to harm anything but not sure how to suppress it.
Any advice would be much appreciated.