Opened 8 years ago

Closed 8 years ago

#27056 closed Bug (fixed)

changing dim property for geometries does not generate correct migration on PostgreSQL

Reported by: Bill Durr Owned by: nobody
Component: Migrations Version: dev
Severity: Normal Keywords: geodjango postgres postgis
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Changing the dim property for a geometry field does not generate a migration that changes the number of dimensions a geometry in the DB has.

Changing a field in a model from models.LineStringField(null=True) to models.LineStringField(null=True, dim=3) creates the following migration and sql:

# -*- coding: utf-8 -*-
# Generated by Django 1.9.8 on 2016-08-12 15:28
from __future__ import unicode_literals

import django.contrib.gis.db.models.fields
from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ('rivermap', '0026_auto_20160624_1827'),
    ]

    operations = [
        migrations.AlterField(
            model_name='sectionextra',
            name='streamPath',
            field=django.contrib.gis.db.models.fields.LineStringField(dim=3, null=True, srid=4326),
        ),
    ]
BEGIN;
--
-- Alter field streamPath on sectionextra
--
ALTER TABLE "rivermap_sectionextra" ALTER COLUMN "streamPath" TYPE geometry(LINESTRINGZ,4326) USING "streamPath"::geometry(LINESTRINGZ,4326);

COMMIT;

This causes an exception during migration because PostGIS returned the following error

Column has Z dimension but geometry does not

According to http://gis.stackexchange.com/questions/109410/postgis-column-has-z-dimension-but-geometry-does-not the ST_Force3D function needs to be used for the USING clause.

Change History (5)

comment:1 by Simon Charette, 8 years ago

Component: UncategorizedMigrations
Triage Stage: UnreviewedAccepted
Version: 1.9master

comment:2 by Claude Paroz, 8 years ago

Has patch: set

I added a pull request to fix this on PostGIS: PR.

On Spatialite, things are currently a bit messy, for several different reasons. It's currently not possible to alter geometry fields on Spatialite. I would suggest to commit the PostGIS changes and to open another ticket specific to Spatialite (which might take longer to solve).

comment:3 by Tim Graham, 8 years ago

Summary: changing dim property for gemotries does not generate correct migrationchanging dim property for geometries does not generate correct migration on PostgreSQL
Triage Stage: AcceptedReady for checkin

Looks good, pending a few cosmetic issues.

comment:4 by Claude Paroz <claude@…>, 8 years ago

In 8e2ac3b:

Refs #27056 -- Rearranged gis_migrations test case classes

comment:5 by Claude Paroz <claude@…>, 8 years ago

Resolution: fixed
Status: newclosed

In 92323d54:

Fixed #27056 -- Allowed migrating geometry field dimension on PostGIS

Thanks Tim Graham for the review.

Note: See TracTickets for help on using tickets.
Back to Top