PostgresqlPython插入,列关系不存在

2024-04-20 00:12:14 发布

您现在位置:Python中文网/ 问答频道 /正文

使用python从IMDB中获取一些著名的电影引用,并将其插入到postgresql数据库中。在刮取数据之后

[['The Godfather', "A man who doesn't spend time with his family can never be a real man", 'Car Wash', '25th Hour', 'Tootsie'], 
['The Usual Suspects', "The greatest trick the devil ever pulled was convincing the world he didn't exist ... and like that, he's gone", 'The Hustler', 'The Good, the Bad and the Ugly', 'Les aventures de Rabbi Jacob'].... ]

表格方案

"Wrong2" character varying COLLATE pg_catalog."default" NOT NULL,
"Wrong1" character varying COLLATE pg_catalog."default" NOT NULL,
"Question" character varying COLLATE pg_catalog."default" NOT NULL,
"Id" integer NOT NULL,
"Answer" character varying COLLATE pg_catalog."default" NOT NULL,
"Wrong3" character varying COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT question_pkey PRIMARY KEY ("Id")

查询

id = None
stmt = "INSERT INTO public.question (Answer, Question, Wrong1, Wrong2, Wrong3) VALUES(%s, %s, %s, %s, %s);"
data = (databaseValueList[0][0], databaseValueList[0][1], databaseValueList[0][2], databaseValueList[0][3], databaseValueList[0][4])
cur.execute(stmt, data)
id = cur.fetchone()[0]
print(id)
conn.commit()
cur.close()

回复

column "answer" of relation "question" does not exist
LINE 1: INSERT INTO public.question (Answer, Question, Wrong1, Wrong...

我试着把它全部改成小写,因为它很重要(我读过,因为我没有使用引号,所以不应该使用引号),强制转换为string str(databaseValueList[0][1])和其他一些东西都没有用。如果您有任何关于解决问题方向的想法,我们将不胜感激。你知道吗


Tags: thedefaultnotnulldatabasecatalogpgquestion