Lev
Lev

Reputation: 1009

psycopg2.ProgrammingError: column of relation does not exist

Trying to insert data into PostgreSQL database.

Python code:

myFields = ((DOT_Number,),(Entity_Type,),(Operating_Status,),(Legal_Name,),
(Phone,),(Address,)
)

query = """ INSERT INTO saferdb_question( DOT_Number, Entity_Type, Operating_Status, Legal_Name, Phone, Address)VALUES ( %s, %s, %s, %s, %s, %s);"""

cur.execute( query, myFields)

Getting error:

Traceback (most recent call last):
  File "scraper.py", line 189, in <module>
    cur.execute( query, myFields)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/psycopg2/extras.py", line 144, in execute
    return super(DictCursor, self).execute(query, vars)
psycopg2.ProgrammingError: column "dot_number" of relation "saferdb_question" does not exist
LINE 1:  INSERT INTO saferdb_question( DOT_Number, Entity_Type, Oper...

SQL from PostgreSQL that created the table:

CREATE TABLE public.saferdb_question
(
    id integer NOT NULL DEFAULT nextval('saferdb_question_id_seq'::regclass),
    "DOT_Number" character varying(10) COLLATE pg_catalog."default" NOT NULL,

...

    "Phone" character varying(15) COLLATE pg_catalog."default" NOT NULL,
    "Address" character varying(200) COLLATE pg_catalog."default" NOT NULL,

)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE public.saferdb_question
    OWNER to postgres;

Upvotes: 2

Views: 8740

Answers (1)

Lev
Lev

Reputation: 1009

Finally solved this. The columns had to be in quotes. Here is the final Query string:

query = """ INSERT INTO public.saferdb_question( "DOT_Number", "Entity_Type", "Operating_Status", "Legal_Name", "Phone", "Address")VALUES ( %s, %s, %s, %s, %s, %s);"""

Upvotes: 2

Related Questions