diff --git a/django/contrib/gis/db/backends/postgis/schema.py b/django/contrib/gis/db/backends/postgis/schema.py
index 7d4c42f..1ef059f 100644
a
|
b
|
class PostGISSchemaEditor(DatabaseSchemaEditor):
|
7 | 7 | geom_index_ops_nd = 'GIST_GEOMETRY_OPS_ND' |
8 | 8 | |
9 | 9 | sql_add_geometry_column = "SELECT AddGeometryColumn(%(table)s, %(column)s, %(srid)s, %(geom_type)s, %(dim)s)" |
| 10 | sql_drop_geometry_column = "SELECT DropGeometryColumn(%(table)s, %(column)s)" |
10 | 11 | sql_alter_geometry_column_not_null = "ALTER TABLE %(table)s ALTER COLUMN %(column)s SET NOT NULL" |
11 | 12 | sql_add_spatial_index = "CREATE INDEX %(index)s ON %(table)s USING %(index_type)s (%(column)s %(ops)s)" |
12 | 13 | |
… |
… |
class PostGISSchemaEditor(DatabaseSchemaEditor):
|
70 | 71 | } |
71 | 72 | ) |
72 | 73 | return column_sql |
| 74 | |
| 75 | def remove_field(self, model, field): |
| 76 | from django.contrib.gis.db.models.fields import GeometryField |
| 77 | if not isinstance(field, GeometryField) or self.connection.ops.spatial_version < (2, 0): |
| 78 | super(PostGISSchemaEditor, self).remove_field(model, field) |
| 79 | |
| 80 | self.execute( |
| 81 | self.sql_drop_geometry_column % { |
| 82 | "table": self.geo_quote_name(model._meta.db_table), |
| 83 | "column": self.geo_quote_name(field.column), |
| 84 | } |
| 85 | ) |
diff --git a/django/contrib/gis/tests/gis_migrations/migrations/0002_add_linestring_field.py b/django/contrib/gis/tests/gis_migrations/migrations/0002_add_linestring_field.py
index 4d7a33a..62803a0 100644
a
|
b
|
class Migration(migrations.Migration):
|
18 | 18 | field=django.contrib.gis.db.models.fields.LineStringField(srid=4326, null=True, blank=True), |
19 | 19 | preserve_default=True, |
20 | 20 | ), |
| 21 | migrations.RemoveField('Neighborhood', 'geom'), |
21 | 22 | ] |
diff --git a/django/contrib/gis/tests/gis_migrations/test_commands.py b/django/contrib/gis/tests/gis_migrations/test_commands.py
index 4766bfc..35b42ec 100644
a
|
b
|
class MigrateTests(TransactionTestCase):
|
30 | 30 | field_names = [info.name for info in self.get_table_description(table)] |
31 | 31 | self.assertIn(field, field_names) |
32 | 32 | |
| 33 | def assertFieldNotExists(self, table, field): |
| 34 | field_names = [info.name for info in self.get_table_description(table)] |
| 35 | self.assertNotIn(field, field_names) |
| 36 | |
33 | 37 | @skipUnless(HAS_SPATIAL_DB, "Spatial db is required.") |
34 | 38 | @override_system_checks([]) |
35 | 39 | @override_settings(MIGRATION_MODULES={"gis": "django.contrib.gis.tests.gis_migrations.migrations"}) |
… |
… |
class MigrateTests(TransactionTestCase):
|
49 | 53 | self.assertTableExists("gis_household") |
50 | 54 | # Run the migrations to 0002 (adding LineString field) |
51 | 55 | call_command("migrate", "gis", "0002", verbosity=0) |
52 | | # Test the new field has been created |
| 56 | # Test the new field has been created, and old one removed |
53 | 57 | self.assertFieldExists("gis_neighborhood", "path") |
| 58 | self.assertFieldNotExists("gis_neighborhood", "geom") |
54 | 59 | # Unmigrate everything |
55 | 60 | call_command("migrate", "gis", "zero", verbosity=0) |
56 | 61 | # Make sure it's all gone |