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