1

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;

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.