从Python向MySQL数据库插入行时出错

时间:2016-06-23 07:43:17

标签: python mysql pymysql

我尝试使用Python更新空的mySQL数据库。

这是我收到的错误:

  

pymysql.err.InternalError:(1416,'无法从发送到GEOMETRY字段的数据中获取几何对象')

这是有问题的代码:

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

这是表格在数据库中的样子(它是空的):

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

看起来你正在使用MySQL类型linestring来表示字符串,而在MySQL中,表示字符串的正确类型将是textvarchar(<some_length>)linestring是几何线的表示,您可以在此处看到:https://dev.mysql.com/doc/refman/5.7/en/gis-linestring-property-functions.html

要解决此问题,只需将namecountry的列类型更改为varchar(<some-length>)text。请参阅:http://dev.mysql.com/doc/refman/5.7/en/char.html

相关问题