我正在尝试使用 Python 更新空的 mySQL 数据库。
这是我收到的错误:
pymysql.err.InternalError: (1416, 'Cannot get geometry object from data you send to the GEOMETRY field')
这是有问题的代码:
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
关于python - 从 Python 向 MySQL 数据库插入行时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37985198/