[英]MySQL error on pythonanywhere when trying to insert record
I'm getting a strange error when I try to register a record on pythonanywhere MySQL.当我尝试在 pythonanywhere MySQL 上注册记录时,我遇到了一个奇怪的错误。
MySQLdb._exceptions.OperationalError: (1136, "Column count doesn't match value count at row 1")
cursor.execute('INSERT INTO accounts VALUES (NULL, %s, %s, %s, %s, %s, %s, NOW())', (username, salt, hashed, email,token,plan,))
Locally it runs fine.在本地运行良好。
DROP TABLE IF EXISTS `accounts`;
CREATE TABLE IF NOT EXISTS `accounts` (
`id` int(16) NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL,
`salt` varchar(29) NOT NULL,
`pw_hash` varchar(60) NOT NULL,
`email` varchar(320) NOT NULL,
`token` varchar(32) NOT NULL,
`plan` varchar(32) NOT NULL,
`last_payment` date DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
You'll need to define the columns your inserting into:您需要定义插入的列:
cursor.execute("INSERT INTO accounts(username, salt, pw_hash, email, token, plan, last_payment) VALUES (%s, %s, %s, %s, %s, %s, NOW())", (username, salt, hashed, email, token, plan))
No need to add a NULL value for id
here - you've defined it as NOT NULL
and AUTO_INCREMENT
, which means MySQL will populate that value for you.无需在此处为
id
添加 NULL 值 - 您已将其定义为NOT NULL
和AUTO_INCREMENT
,这意味着 MySQL 将为您填充该值。
Your tuple has a comma too much.你的元组有太多逗号。
simply remove it只需将其删除
cursor.execute('INSERT INTO accounts VALUES (NULL, %s, %s, %s, %s, %s, %s, NOW())', (username, salt, hashed, email,token,plan))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.