I'm getting a strange error when I try to register a record on 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;
CodePudding user response:
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.
CodePudding user response:
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))