gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 23:29:11 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com