#36129: Geodjango migrations ignore change of dimension in MultiPointField
------------------------------+-----------------------------------------
Reporter: Paweł Kotiuk | Type: Uncategorized
Status: new | Component: GIS
Version: 5.1 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+-----------------------------------------
I think I found a bug in GeoDjango migration mechanism.
== Reproduction
1. Create a simple model
{{{#!div style="font-size: 80%"
{{{#!python
class MultiPointTester(models.Model):
multipoint = models.MultiPointField(
dim=2,
blank=True,
null=True,
default="SRID=4326;MULTIPOINT EMPTY",
)
}}}
}}}
and test for it
{{{#!div style="font-size: 80%"
{{{#!python
class MultipointTest(TransactionTestCase):
def test_multipoint_creation(self):
instance = models.MultiPointTester()
instance.save()
self.assertEqual(instance.multipoint.ewkt, "SRID=4326;MULTIPOINT
EMPTY")
}}}
}}}
2. Generate migration for it `./manage.py makemigrations`
3. Run test - it succeeds ✅
4. Change dim from 2 to 3 and create migration
It contains migration like this (it does not mention dim change):
{{{#!div style="font-size: 80%"
{{{#!python
operations = [
migrations.AlterField(
model_name='multipointtester',
name='multipoint',
field=django.contrib.gis.db.models.fields.MultiPointField(
blank=True,
default='SRID=4326;MULTIPOINT EMPTY',
null=True, srid=4326),
),
]
}}}
}}}
6. Run test again - it fails ❌ with error:
`E ValueError: Cannot alter field
test.MultiPointTester.multipoint into test.MultiPointTester.multipoint -
they do not properly define db_type (are you using a badly-written custom
field?)`
7. Remove all existing migration files and again generate migration
`./manage.py makemigrations`
8. Run test again - - it succeeds ✅
Is is a bug, or do I make some kind of mistake in the code?
--
Ticket URL: <https://code.djangoproject.com/ticket/36129>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019493af54d0-4e9a45b0-bcc4-4910-9337-c3c9ef1f3ea0-000000%40eu-central-1.amazonses.com.