1

我有一个有 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

如何解决?

4

3 回答 3

0

试试这个:

tx.execute(\
            "insert into company_career (date_entered) "
            "values (FROM_UNIXTIME('%s'))",
            (time.time())
        )
于 2012-07-22T18:14:14.117 回答
0

当您在插入查询中提供值时,不要忘记用逗号将其括起来

"insert into company_career (date_entered) values ('%s')"
于 2012-07-23T04:08:07.807 回答
0

我确实设法插入: insert into company(url,mail,date_entered) values("","","now");

于 2012-08-26T09:49:55.827 回答