0

when I try to makemigrate models with Geometry fields to postgres DB I face with next message:

You are trying to change the nullable field 'geom' on allotment to non-nullable without a default; we can't do that (the database needs something to populate existing rows).

OK, set default = ' ', or something like 'MULTIPOLIGON (((0. 0. 0. 0. 0.)))' and when I wish to migrate terminal throws this:

    ..File "/home/user/MyProjects/forest-venv/lib/python3.5/site-packages/django/contrib/gis/geos/geometry.py", line 697, in __init__
    raise ValueError('String input unrecognized as WKT EWKT, and HEXEWKB.')
ValueError: String input unrecognized as WKT EWKT, and HEXEWKB.

An examples of my classes with geometry:

class ForestryKeys(models.Model):

id = models.IntegerField(primary_key=True)
name = models.TextField(blank=True, null=True), 
geom = models.MultiPolygonField(verbose_name='geo',srid = 4326)

class Meta:
    managed = True
    verbose_name = 'geo'
    verbose_name_plural =  'geos'

class DistrForestKeys(models.Model):

id = models.IntegerField(primary_key=True)
df_names = models.TextField(blank=True, null=True)
geom = models.MultiPolygonField(verbose_name='polygs',srid = 4326)
forestry_id = models.ForeignKey(ForestryKeys, models.DO_NOTHING, blank=True, null=True)

class Meta:
    managed = True
    verbose_name = 'ULV'
    verbose_name_plural =  'ULVs'

etc.

Why I have to set default value? and how it do correct for diffrient geometry types?

0

Your problem should disappear if you allow the geometry field to be null like this:

geom = models.MultiPolygonField(verbose_name='geo',srid = 4326, null=True, blank=True)

If you prefer a non-nullable field, use a valid default. Your multipolygon declaration is not valid WKT as the error states.

  • You have a typo in the type name (multipolygon vs multipoligon)
  • You need to describe a full polygon in your default

Try using an empty polygon

"MULTIPOLYGON EMPTY"

or a valid dummy polygon

"MULTIPOLYGON (((0 0, 0 1, 1 1, 1 0, 0 0)))"
  • my code started work after set geographu = True – Tyomik_mnemonic Mar 13 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.