python - 无法将数据插入具有默认值的表

标签 python mysql scrapy

我有一个包含 4 个属性的表。

    +--------------+--------------+------+-----+-------------------+----------------+
| Field        | Type         | Null | Key | Default           | Extra          |
+--------------+--------------+------+-----+-------------------+----------------+
| id           | int(11)      | NO   | PRI | NULL              | auto_increment |
| url          | varchar(255) | YES  |     | NULL              |                |
| mail         | varchar(255) | YES  |     | NULL              |                |
| date_entered | timestamp    | NO   |     | CURRENT_TIMESTAMP |                |
| active       | tinyint(1)   | NO   |     | 1                 |                |
+--------------+--------------+------+-----+-------------------+----------------+

现在我只想插入 data_entered 和其他属性以获得默认值。 我正在为 id 字段执行此操作,我需要与插入到不同表中的另一个 id 完全一致。

这是代码:

        tx.execute(\
            "insert into company_career (date_entered) "
            "values (%s)",
            (time.time())
        )

这是错误:

        query = query % db.literal(args)
    exceptions.TypeError: not all arguments converted during string formatting

如何解决?

最佳答案

试试这个:

tx.execute(\
            "insert into company_career (date_entered) "
            "values (FROM_UNIXTIME('%s'))",
            (time.time())
        )

关于python - 无法将数据插入具有默认值的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11602647/

相关文章:

php - 带下一个/上一个按钮的下拉菜单 php

mysql - 使用 Sean lahman MLB 数据库了解 mysql 查询性能

python - 从 scrapy 爬虫获取空结果

redirect - Scrapy 处理 302 响应代码

python - 创建新的 jupyter 笔记本 : 500: Internal Server Error

python - ANTLR 语法后缀

Python:如何将两个平面列表组合成一个二维数组?

Python:如何使用原始列表中的某些按字母顺序排列的项目创建新列表?

php - Symfony2 学说 : How to select users that are not in groups with doctrine query builder

python - 如何在scrapy中处理302重定向