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

标签 python mysql pymysql

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

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

enter image description here

enter image description here

最佳答案

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

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

关于python - 从 Python 向 MySQL 数据库插入行时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37985198/

相关文章:

python - 在一个 DAG 中执行顺序和并发任务

python - PyMySQL 频繁读取后抛出 'BrokenPipeError'

python - 如何获取有序集?

python - 使用 Python 在 3D 无噪声标量场中寻找峰值

php - 在 mysql 的 php 查询中是否有任何 msi 关键字或特殊作用?

php - 在查询中计数两次,一次使用限制

php - 我的基于 php + mysql 的表单需要一些帮助

python - 用于 celery 的原始 PyMySQL 多线程

mysql - 1054,字段列表中的未知列 'index'

python - 将 .split() 函数与 urllib.request 一起使用时出错