Nate Nate - 4 months ago 29x
SQL Question

Error when inserting row into MySQL database from Python

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:

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'))



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

enter image description here

enter image description here


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:

To fix this, simply change the column types of name and country to varchar(<some-length>) or text. See: