Error while running my code at mission 114-5

Hello
while running my code at the 114-5 mission

conn = psycopg2.connect(“dbname=dq user=dq”)
cur = conn.cursor()
cur.execute(“CREATE TABLE notes(id integer PRIMARY KEY, body text, title text)”)
conn.commit()
conn.close()

I get this error at the end:

ProgrammingErrorTraceback (most recent call last)
in ()
1 conn = psycopg2.connect(“dbname=dq user=dq”)
2 cur = conn.cursor()
----> 3 cur.execute(“CREATE TABLE notes(id integer PRIMARY KEY, body text, title text)”)
4 conn.commit()
5 conn.close()

ProgrammingError: relation “notes” already exists

Any suggestions?

Thank you

1 Like

I’ve made a change in my code and it passed.

conn = psycopg2.connect(“dbname=dq user=dq”)
cur = conn.cursor()
cur.execute(“drop TABLE notes;”)
cur.execute(“CREATE TABLE notes(id integer PRIMARY KEY, body text, title text);”)
conn.commit()
conn.close()

Must have keeped the notes table from the previous screen so I have to drop it and recreate it.

Does that sound right?

4 Likes

hey @georgegazanis

yes, that’s right. :+1:

Hi george, I had the exact same issue, thanks for the tip!
Nicolas

Thanks George - I suspected this was the problem and running the DROP and CREATE commands within the same transaction did the trick.