[英]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中,表示字符串的正确类型将是text
或varchar(<some_length>)
。 linestring
是几何线的表示,如您在此处所见: https : //dev.mysql.com/doc/refman/5.7/en/gis-linestring-property-functions.html
要解决此问题,只需将name
和country
的列类型更改为varchar(<some-length>)
或text
。 参见: http : //dev.mysql.com/doc/refman/5.7/en/char.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.