0

I'm trying to update an empty mySQL database using Python.

This is the error I receive:

pymysql.err.InternalError: (1416, 'Cannot get geometry object from data you send to the GEOMETRY field')

Here's the problematic code:

try:
    with connection.cursor() as cursor:
        # Create a new record
        sql = "INSERT INTO `projects` (`name`, `country`,  `activation_date`, `active`) VALUES (%s, %s, %s, %s)"
        cursor.execute(sql, ('Nate', 'USA', '2016-06-23 09:11:32', '1'))

    connection.commit()

finally:
    connection.close()

Here is what the table looks like in the database (it's empty):

enter image description here

enter image description here

2
  • Could you include the table's definition (including indexes and triggers)? It's not quite obvious from your post what raises the error. Commented Jun 23, 2016 at 7:49
  • 1
    Yes, I think you're using the datatype LineString the wrong way and meant to use a varchar or text type. A LineString consists of Points and is meant for spatial data, not text. Commented Jun 23, 2016 at 8:00

1 Answer 1

1

It looks like you're using the MySQL type linestring to represent a string, while in MySQL the correct type to represent a string of characters would be text or varchar(<some_length>). linestring is a representation of a geometric line, as you can see here: https://dev.mysql.com/doc/refman/5.7/en/gis-linestring-property-functions.html

To fix this, simply change the column types of name and country to varchar(<some-length>) or text. See: http://dev.mysql.com/doc/refman/5.7/en/char.html

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks everyone, this fixed it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.