繁体   English   中英

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

[英]Error when inserting row into MySQL database from Python

我正在尝试使用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()

这是数据库中表的外观(它为空):

在此处输入图片说明

在此处输入图片说明

看起来您正在使用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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM