0

Note: Copying and elaborating upon this question and answer from: https://groups.google.com/forum/?fromgroups=#!topic/django-users/OW_uSWCoObs:

Hi, I was trying to go through the GeoDjango tutorial and when I try to import data with LayerMapping I'm getting the following error:

  Warning: Incorrect string value: '\xC2\x85land...' for column 'name' at row 1

I'm using MySQL and my charset and collation are set to latin1 (I also tried utf8).

Dmitry Minkovsky
  • 36,185
  • 26
  • 116
  • 160

1 Answers1

0

Inserting iso-8859-1 (latin1) characters into a utf8 column causes MySQL to throw that error.

This can be solved by changing the encoding in the line in the tutorial for world/load.py from this:

lm = LayerMapping(WorldBorder, world_shp, world_mapping,
                  transform=False, encoding='iso-8859-1')

To the following ...

lm = LayerMapping(WorldBorder, world_shp, world_mapping,
                  transform=False, encoding='utf8')

For more, see MySQL "incorrect string value" error when save unicode string in Django

Generally, see http://bugs.mysql.com/bug.php?id=30131 for more detail, particularly if you are a Windows user (don't be mislead by the URL—this is not a bug).

Community
  • 1
  • 1
Dmitry Minkovsky
  • 36,185
  • 26
  • 116
  • 160