Hello,
I think I found a bug in GeoDjango migration mechanism.
Reproduction
- Create a simple model
class MultiPointTester(models.Model):
multipoint = models.MultiPointField(
dim=2,
blank=True,
null=True,
default="SRID=4326;MULTIPOINT EMPTY",
)
and test for it
class MultipointTest(TransactionTestCase):
def test_multipoint_creation(self):
instance = models.MultiPointTester()
instance.save()
self.assertEqual(instance.multipoint.ewkt, "SRID=4326;MULTIPOINT EMPTY")
- Generate migration for it
./manage.py makemigrations
- Run test - it succeeds
- Change dim from 2 to 3 and create migration
It contains migration like this (it does not mention dim change):
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),
),
]
- 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?)
- Remove all existing migration files and again generate migration
./manage.py makemigrations
- Run test again - - it succeeds
Is is a bug, or do I make some kind of mistake in the code?