我的程序在执行插入数据库的函数后向我发送以下错误消息:
Traceback:
`Traceback (most recent call last):
File "C:\Python33\Archive\MySQL-teste12.py", line 275, in <module>
inserir(cursor, cx2)
File "C:\Python33\Archive\MySQL-teste12.py", line 193, in inserir
cursor.execute(add_produto)
File "C:\Python33\lib\site-packages\mysql\connector\cursor.py", line 415, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "C:\Python33\lib\site-packages\mysql\connector\connection.py", line 593, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "C:\Python33\lib\site-packages\mysql\connector\connection.py", line 515, in _handle_result
raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 1054 (42S22): Unknown column 'd' in 'field list'`
正在尝试插入下表:
produto = """
CREATE TABLE produto (
prod_nu int(11) NOT NULL AUTO_INCREMENT,
nome varchar(30) NOT NULL,
data_lcm date NOT NULL,
preco int(11) NOT NULL,
PRIMARY KEY (prod_nu)
) ENGINE=InnoDB
"""
这是发生错误的过程。我相信它不接受任何日期格式。我尝试了很多变体,但都没有奏效:
def inserir (cursor, db):
# excess code removed
vb = input('Digite a data de Lançamento do Produto (Ano/mês/dia).')
now = time.strftime('vb')
…
add_produto = ("""INSERT INTO produto(nome,
data_lcm, preco)
VALUES (%s, %s, %s)""" % (va,vb,vc))
cursor.execute(add_produto)
…