pymysql.err.OperationalError: (1241, 'Operand should contain 1 column(s)'). I can't determine a mistake
pymysql.err.OperationalError: (1241, 'Operand should contain 1 column(s)'). I can't determine a mistake
with connection:
with connection.cursor() as cursor:
window = Tk()
window.title('Data change')
window.geometry('500x300')
title1 = input('Name of film: ')
country1 = input('Country: ')
year1 = int(input('Year: '))
duration1 = int(input('Duration: '))
clicked2 = input('Genre: ')
clicked3 = int(input('Director ID: '))
sql = """insert into Film(director_id, title, genre, year, country, duration_in_min) values((select * from Director where Id = %s),%s, %s, %s, %s, %s);"""
var = (title1, clicked2, year1, country1, duration1, clicked3)
cursor.execute(sql, var)
connection.commit()
我无法确定这段代码中的错误到底是什么。
您在值子句中有以下子查询:
(select * from Director where Id = %s)
此子查询可能 returns 不止一列,这会触发错误消息。您应该 select 只有 1 列,或者直接使用 director id 而无需子查询。
您的参数顺序与插入字段列表中的字段顺序不匹配。例如,插入中的第一个字段是 director_id
,但您在参数数组的第一个位置传递 title1
参数。
with connection:
with connection.cursor() as cursor:
window = Tk()
window.title('Data change')
window.geometry('500x300')
title1 = input('Name of film: ')
country1 = input('Country: ')
year1 = int(input('Year: '))
duration1 = int(input('Duration: '))
clicked2 = input('Genre: ')
clicked3 = int(input('Director ID: '))
sql = """insert into Film(director_id, title, genre, year, country, duration_in_min) values((select * from Director where Id = %s),%s, %s, %s, %s, %s);"""
var = (title1, clicked2, year1, country1, duration1, clicked3)
cursor.execute(sql, var)
connection.commit()
我无法确定这段代码中的错误到底是什么。
您在值子句中有以下子查询:
(select * from Director where Id = %s)
此子查询可能 returns 不止一列,这会触发错误消息。您应该 select 只有 1 列,或者直接使用 director id 而无需子查询。
您的参数顺序与插入字段列表中的字段顺序不匹配。例如,插入中的第一个字段是 director_id
,但您在参数数组的第一个位置传递 title1
参数。