MySQLdb._exceptions.OperationalError: (1136, "Column count doesn't match value count at row 1")
MySQLdb._exceptions.OperationalError: (1136, "Column count doesn't match value count at row 1")
我试图从以下 html 表单中提取一堆值到 python 中,然后再到 MySQL 数据库中,但不断遇到“
MySQLdb._exceptions.OperationalError: (1136, "Column count doesn't
match value count at row 1"):
”错误代码。我尝试添加主键(id,auto_increment)但它似乎对问题没有任何影响。
以下是相关摘录:
@app.route('/character/new', methods=['GET', 'POST'])
@is_logged_in
def character_new():
cur = mysql.connection.cursor()
if request.method == 'POST':
image = "NULL"
userid = get_userid()
character_name = request.form['character_name']
alignment = request.form['alignment']
race = request.form['race']
_class = request.form['class']
sex = request.form['sex']
level = request.form['level']
experience = request.form['experience']
stat_str = request.form['stat_str']
stat_dex = request.form['stat_dex']
stat_con = request.form['stat_con']
stat_int = request.form['stat_int']
stat_wis = request.form['stat_wis']
stat_cha = request.form['stat_cha']
mod_str = request.form['mod_str']
mod_dex = request.form['mod_dex']
mod_con = request.form['mod_con']
mod_int = request.form['mod_int']
mod_wis = request.form['mod_wis']
mod_cha = request.form['mod_cha']
sav_str = request.form['sav_str']
sav_dex = request.form['sav_dex']
sav_con = request.form['sav_con']
sav_int = request.form['sav_int']
sav_wis = request.form['sav_wis']
sav_cha = request.form['sav_cha']
hitpoints = request.form['hitpoints']
armor_class = request.form['armor_class']
cur_hitpoints = request.form['cur_hitpoints']
speed = request.form['speed']
initiative = request.form['initiative']
prof_bonus = request.form['prof_bonus']
ski_aco = request.form['ski_aco']
ski_ani = request.form['ski_ani']
ski_arc = request.form['ski_arc']
ski_ath = request.form['ski_ath']
ski_dec = request.form['ski_dec']
ski_his = request.form['ski_his']
ski_ins = request.form['ski_ins']
ski_int = request.form['ski_int']
ski_inv = request.form['ski_inv']
ski_med = request.form['ski_med']
ski_nat = request.form['ski_nat']
ski_per = request.form['ski_per']
ski_pef = request.form['ski_pef']
ski_pes = request.form['ski_pes']
ski_rel = request.form['ski_rel']
ski_soh = request.form['ski_soh']
ski_sth = request.form['ski_sth']
ski_sur = request.form['ski_sur']
prof_trait_abi = request.form['prof_trait_abi']
languages = request.form['languages']
items = request.form['items']
equipment = request.form['equipment']
treasures = request.form['treasures']
wep_1 = request.form['wep_1']
wep_2 = request.form['wep_2']
wep_3 = request.form['wep_3']
wep_4 = request.form['wep_4']
att_1 = request.form['att_1']
att_2 = request.form['att_2']
att_3 = request.form['att_3']
att_4 = request.form['att_4']
dmg_1 = request.form['dmg_1']
dmg_2 = request.form['dmg_2']
dmg_3 = request.form['dmg_3']
dmg_4 = request.form['dmg_4']
typ_1 = request.form['typ_1']
typ_2 = request.form['typ_2']
typ_3 = request.form['typ_3']
typ_4 = request.form['typ_4']
amm_1 = request.form['amm_1']
amm_2 = request.form['amm_2']
amm_3 = request.form['amm_3']
amt_1 = request.form['amt_1']
amt_2 = request.form['amt_2']
amt_3 = request.form['amt_3']
spl_1 = request.form['spl_1']
spl_2 = request.form['spl_2']
spl_3 = request.form['spl_3']
spl_4 = request.form['spl_4']
spl_att_1 = request.form['spl_att_1']
spl_att_2 = request.form['spl_att_2']
spl_att_3 = request.form['spl_att_3']
spl_att_4 = request.form['spl_att_4']
spl_dmg_1 = request.form['spl_dmg_1']
spl_dmg_2 = request.form['spl_dmg_2']
spl_dmg_3 = request.form['spl_dmg_3']
spl_dmg_4 = request.form['spl_dmg_4']
values=(image, userid, character_name, alignment, race, _class, sex, level, experience,stat_str, stat_dex, stat_con, stat_int, stat_wis, stat_cha, mod_str, mod_str, mod_dex, mod_con, mod_int, mod_wis, mod_cha,sav_str, sav_dex, sav_con, sav_int, sav_wis, sav_cha, hitpoints, armor_class, cur_hitpoints, speed, initiative, prof_bonus, ski_aco, ski_ani, ski_arc, ski_ath, ski_dec, ski_his, ski_ins, ski_int, ski_inv, ski_med, ski_nat, ski_per, ski_pef, ski_pes, ski_rel, ski_soh, ski_sth, ski_sur, prof_trait_abi, languages, items, equipment, treasures, wep_1, wep_2, wep_3, wep_4, att_1, att_2, att_3, att_4, dmg_1, dmg_2, dmg_3, dmg_4, typ_1, typ_2, typ_3, typ_4, amm_1, amm_2, amm_3, amt_1, amt_2, amt_3, spl_1,spl_2, spl_3, spl_4, spl_att_1, spl_att_2, spl_att_3, spl_att_3, spl_att_4, spl_dmg_1, spl_dmg_2, spl_dmg_3, spl_dmg_4)
cur.execute("INSERT INTO characters(image, userid, character_name, alignment, race, class, sex, level, experience, stat_str, stat_dex, stat_con, stat_int, stat_wis, stat_cha, mod_str, mod_dex, mod_con, mod_int, mod_wis, mod_cha, sav_str, sav_dex, sav_con, sav_int, sav_wis, sav_cha, hitpoints, armor_class, cur_hitpoints, speed, initiative, prof_bonus, ski_aco, ski_ani, ski_arc, ski_ath, ski_dec, ski_his, ski_ins, ski_int, ski_inv, ski_med, ski_nat, ski_per, ski_pef, ski_pes, ski_rel, ski_soh, ski_sth, ski_sur, prof_trait_abi, languages, items, equipment, treasures, wep_1, wep_2, wep_3, wep_4, att_1, att_2, att_3, att_4, dmg_1, dmg_2, dmg_3, dmg_4, typ_1, typ_2, typ_3, amm_1, amm_2,amm_3, amt_1, amt_2, amt_3, spl_1, spl_2, spl_3, spl_4, spl_att_1, spl_att_2, spl_att_3, spl_att_4, spl_dmg_1, spl_dmg_2, spl_dmg_3, spl_dmg_4) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", values)
mysql.connection.commit()
cur.close()
flash("Success", "success")
else:
flash("ERROR", "danger")
cur.close()
return render_template('character_new.html')
HTML表格
https://pastebin.com/XFQrubHi
MySQL Table
https://pastebin.com/qwqVCu7a
在此先感谢您的帮助!
您在 values
元组中有两次 spl_att_3
和 mod_str
。并且缺少要插入的列列表 typ_4
。
values=(image, userid, character_name, alignment, race, _class, sex, level, experience,stat_str, stat_dex, stat_con, stat_int, stat_wis, stat_cha, mod_str, mod_dex, mod_con, mod_int, mod_wis, mod_cha,sav_str, sav_dex, sav_con, sav_int, sav_wis, sav_cha, hitpoints, armor_class, cur_hitpoints, speed, initiative, prof_bonus, ski_aco, ski_ani, ski_arc, ski_ath, ski_dec, ski_his, ski_ins, ski_int, ski_inv, ski_med, ski_nat, ski_per, ski_pef, ski_pes, ski_rel, ski_soh, ski_sth, ski_sur, prof_trait_abi, languages, items, equipment, treasures, wep_1, wep_2, wep_3, wep_4, att_1, att_2, att_3, att_4, dmg_1, dmg_2, dmg_3, dmg_4, typ_1, typ_2, typ_3, typ_4, amm_1, amm_2, amm_3, amt_1, amt_2, amt_3, spl_1,spl_2, spl_3, spl_4, spl_att_1, spl_att_2, spl_att_3, spl_att_4, spl_dmg_1, spl_dmg_2, spl_dmg_3, spl_dmg_4)
cur.execute("INSERT INTO characters(image, userid, character_name, alignment, race, class, sex, level, experience, stat_str, stat_dex, stat_con, stat_int, stat_wis, stat_cha, mod_str, mod_dex, mod_con, mod_int, mod_wis, mod_cha, sav_str, sav_dex, sav_con, sav_int, sav_wis, sav_cha, hitpoints, armor_class, cur_hitpoints, speed, initiative, prof_bonus, ski_aco, ski_ani, ski_arc, ski_ath, ski_dec, ski_his, ski_ins, ski_int, ski_inv, ski_med, ski_nat, ski_per, ski_pef, ski_pes, ski_rel, ski_soh, ski_sth, ski_sur, prof_trait_abi, languages, items, equipment, treasures, wep_1, wep_2, wep_3, wep_4, att_1, att_2, att_3, att_4, dmg_1, dmg_2, dmg_3, dmg_4, typ_1, typ_2, typ_3, type_4, amm_1, amm_2,amm_3, amt_1, amt_2, amt_3, spl_1, spl_2, spl_3, spl_4, spl_att_1, spl_att_2, spl_att_3, spl_att_4, spl_dmg_1, spl_dmg_2, spl_dmg_3, spl_dmg_4) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", values)
我试图从以下 html 表单中提取一堆值到 python 中,然后再到 MySQL 数据库中,但不断遇到“
MySQLdb._exceptions.OperationalError: (1136, "Column count doesn't match value count at row 1"):
”错误代码。我尝试添加主键(id,auto_increment)但它似乎对问题没有任何影响。
以下是相关摘录:
@app.route('/character/new', methods=['GET', 'POST'])
@is_logged_in
def character_new():
cur = mysql.connection.cursor()
if request.method == 'POST':
image = "NULL"
userid = get_userid()
character_name = request.form['character_name']
alignment = request.form['alignment']
race = request.form['race']
_class = request.form['class']
sex = request.form['sex']
level = request.form['level']
experience = request.form['experience']
stat_str = request.form['stat_str']
stat_dex = request.form['stat_dex']
stat_con = request.form['stat_con']
stat_int = request.form['stat_int']
stat_wis = request.form['stat_wis']
stat_cha = request.form['stat_cha']
mod_str = request.form['mod_str']
mod_dex = request.form['mod_dex']
mod_con = request.form['mod_con']
mod_int = request.form['mod_int']
mod_wis = request.form['mod_wis']
mod_cha = request.form['mod_cha']
sav_str = request.form['sav_str']
sav_dex = request.form['sav_dex']
sav_con = request.form['sav_con']
sav_int = request.form['sav_int']
sav_wis = request.form['sav_wis']
sav_cha = request.form['sav_cha']
hitpoints = request.form['hitpoints']
armor_class = request.form['armor_class']
cur_hitpoints = request.form['cur_hitpoints']
speed = request.form['speed']
initiative = request.form['initiative']
prof_bonus = request.form['prof_bonus']
ski_aco = request.form['ski_aco']
ski_ani = request.form['ski_ani']
ski_arc = request.form['ski_arc']
ski_ath = request.form['ski_ath']
ski_dec = request.form['ski_dec']
ski_his = request.form['ski_his']
ski_ins = request.form['ski_ins']
ski_int = request.form['ski_int']
ski_inv = request.form['ski_inv']
ski_med = request.form['ski_med']
ski_nat = request.form['ski_nat']
ski_per = request.form['ski_per']
ski_pef = request.form['ski_pef']
ski_pes = request.form['ski_pes']
ski_rel = request.form['ski_rel']
ski_soh = request.form['ski_soh']
ski_sth = request.form['ski_sth']
ski_sur = request.form['ski_sur']
prof_trait_abi = request.form['prof_trait_abi']
languages = request.form['languages']
items = request.form['items']
equipment = request.form['equipment']
treasures = request.form['treasures']
wep_1 = request.form['wep_1']
wep_2 = request.form['wep_2']
wep_3 = request.form['wep_3']
wep_4 = request.form['wep_4']
att_1 = request.form['att_1']
att_2 = request.form['att_2']
att_3 = request.form['att_3']
att_4 = request.form['att_4']
dmg_1 = request.form['dmg_1']
dmg_2 = request.form['dmg_2']
dmg_3 = request.form['dmg_3']
dmg_4 = request.form['dmg_4']
typ_1 = request.form['typ_1']
typ_2 = request.form['typ_2']
typ_3 = request.form['typ_3']
typ_4 = request.form['typ_4']
amm_1 = request.form['amm_1']
amm_2 = request.form['amm_2']
amm_3 = request.form['amm_3']
amt_1 = request.form['amt_1']
amt_2 = request.form['amt_2']
amt_3 = request.form['amt_3']
spl_1 = request.form['spl_1']
spl_2 = request.form['spl_2']
spl_3 = request.form['spl_3']
spl_4 = request.form['spl_4']
spl_att_1 = request.form['spl_att_1']
spl_att_2 = request.form['spl_att_2']
spl_att_3 = request.form['spl_att_3']
spl_att_4 = request.form['spl_att_4']
spl_dmg_1 = request.form['spl_dmg_1']
spl_dmg_2 = request.form['spl_dmg_2']
spl_dmg_3 = request.form['spl_dmg_3']
spl_dmg_4 = request.form['spl_dmg_4']
values=(image, userid, character_name, alignment, race, _class, sex, level, experience,stat_str, stat_dex, stat_con, stat_int, stat_wis, stat_cha, mod_str, mod_str, mod_dex, mod_con, mod_int, mod_wis, mod_cha,sav_str, sav_dex, sav_con, sav_int, sav_wis, sav_cha, hitpoints, armor_class, cur_hitpoints, speed, initiative, prof_bonus, ski_aco, ski_ani, ski_arc, ski_ath, ski_dec, ski_his, ski_ins, ski_int, ski_inv, ski_med, ski_nat, ski_per, ski_pef, ski_pes, ski_rel, ski_soh, ski_sth, ski_sur, prof_trait_abi, languages, items, equipment, treasures, wep_1, wep_2, wep_3, wep_4, att_1, att_2, att_3, att_4, dmg_1, dmg_2, dmg_3, dmg_4, typ_1, typ_2, typ_3, typ_4, amm_1, amm_2, amm_3, amt_1, amt_2, amt_3, spl_1,spl_2, spl_3, spl_4, spl_att_1, spl_att_2, spl_att_3, spl_att_3, spl_att_4, spl_dmg_1, spl_dmg_2, spl_dmg_3, spl_dmg_4)
cur.execute("INSERT INTO characters(image, userid, character_name, alignment, race, class, sex, level, experience, stat_str, stat_dex, stat_con, stat_int, stat_wis, stat_cha, mod_str, mod_dex, mod_con, mod_int, mod_wis, mod_cha, sav_str, sav_dex, sav_con, sav_int, sav_wis, sav_cha, hitpoints, armor_class, cur_hitpoints, speed, initiative, prof_bonus, ski_aco, ski_ani, ski_arc, ski_ath, ski_dec, ski_his, ski_ins, ski_int, ski_inv, ski_med, ski_nat, ski_per, ski_pef, ski_pes, ski_rel, ski_soh, ski_sth, ski_sur, prof_trait_abi, languages, items, equipment, treasures, wep_1, wep_2, wep_3, wep_4, att_1, att_2, att_3, att_4, dmg_1, dmg_2, dmg_3, dmg_4, typ_1, typ_2, typ_3, amm_1, amm_2,amm_3, amt_1, amt_2, amt_3, spl_1, spl_2, spl_3, spl_4, spl_att_1, spl_att_2, spl_att_3, spl_att_4, spl_dmg_1, spl_dmg_2, spl_dmg_3, spl_dmg_4) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", values)
mysql.connection.commit()
cur.close()
flash("Success", "success")
else:
flash("ERROR", "danger")
cur.close()
return render_template('character_new.html')
HTML表格 https://pastebin.com/XFQrubHi
MySQL Table https://pastebin.com/qwqVCu7a
在此先感谢您的帮助!
您在 values
元组中有两次 spl_att_3
和 mod_str
。并且缺少要插入的列列表 typ_4
。
values=(image, userid, character_name, alignment, race, _class, sex, level, experience,stat_str, stat_dex, stat_con, stat_int, stat_wis, stat_cha, mod_str, mod_dex, mod_con, mod_int, mod_wis, mod_cha,sav_str, sav_dex, sav_con, sav_int, sav_wis, sav_cha, hitpoints, armor_class, cur_hitpoints, speed, initiative, prof_bonus, ski_aco, ski_ani, ski_arc, ski_ath, ski_dec, ski_his, ski_ins, ski_int, ski_inv, ski_med, ski_nat, ski_per, ski_pef, ski_pes, ski_rel, ski_soh, ski_sth, ski_sur, prof_trait_abi, languages, items, equipment, treasures, wep_1, wep_2, wep_3, wep_4, att_1, att_2, att_3, att_4, dmg_1, dmg_2, dmg_3, dmg_4, typ_1, typ_2, typ_3, typ_4, amm_1, amm_2, amm_3, amt_1, amt_2, amt_3, spl_1,spl_2, spl_3, spl_4, spl_att_1, spl_att_2, spl_att_3, spl_att_4, spl_dmg_1, spl_dmg_2, spl_dmg_3, spl_dmg_4)
cur.execute("INSERT INTO characters(image, userid, character_name, alignment, race, class, sex, level, experience, stat_str, stat_dex, stat_con, stat_int, stat_wis, stat_cha, mod_str, mod_dex, mod_con, mod_int, mod_wis, mod_cha, sav_str, sav_dex, sav_con, sav_int, sav_wis, sav_cha, hitpoints, armor_class, cur_hitpoints, speed, initiative, prof_bonus, ski_aco, ski_ani, ski_arc, ski_ath, ski_dec, ski_his, ski_ins, ski_int, ski_inv, ski_med, ski_nat, ski_per, ski_pef, ski_pes, ski_rel, ski_soh, ski_sth, ski_sur, prof_trait_abi, languages, items, equipment, treasures, wep_1, wep_2, wep_3, wep_4, att_1, att_2, att_3, att_4, dmg_1, dmg_2, dmg_3, dmg_4, typ_1, typ_2, typ_3, type_4, amm_1, amm_2,amm_3, amt_1, amt_2, amt_3, spl_1, spl_2, spl_3, spl_4, spl_att_1, spl_att_2, spl_att_3, spl_att_4, spl_dmg_1, spl_dmg_2, spl_dmg_3, spl_dmg_4) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", values)