2

I am making a project where I connect to a database with Python then update and change things. I have run into problems when trying to retrieve information.

I am using this code:

import sqlite3
conn = sqlite3.connect('Project.db')

print ("Opened database sucessfully")

cursor = conn.execute("SELECT ID,ResidentTitle,ResidentForname FROM Residents")
for row in cursor:
    print ("ID = "), row[0]
    print ("ResidentTitle ="), row[1]
    print ("Name ="), row[2]

print ("done");
conn.close()

from this I am getting back the error:

Traceback (most recent call last):
File "C:/sqlite/Sqlplz.py", line 7, in <module>
cursor = conn.execute("SELECT ID,ResidentTitle,ResidentForname FROM Residents")
sqlite3.OperationalError: no such table: Residents

How can I resolve this error?

5
  • You are missing space. FROMResidents must be FROM Residents Commented Nov 25, 2015 at 16:27
  • @Alexander: the SQL in your code doesn't match the SQL in the error message; double-check that they're both up-to-date? Commented Nov 25, 2015 at 16:37
  • @nickgrim updated thank you. Commented Nov 25, 2015 at 16:38
  • 1
    Wait, where is the confusion? Error message says everything. There is no table Residents in the database. Commented Nov 25, 2015 at 16:39
  • Is the file Project.db in the current directory? If not, then the connect statement creates a new empty database. Commented Nov 25, 2015 at 17:49

2 Answers 2

1
cursor = conn.execute("SELECT ID,ResidentTitle,ResidentForname FROMResidents")
-------------------------------------------------------------------^

You are missing space, you should update like that

cursor = conn.execute("SELECT ID,ResidentTitle,ResidentForname FROM Residents")
Sign up to request clarification or add additional context in comments.

2 Comments

i uploaded the wrong code, i updated the problem, sorry.
@Alexander, did you create Residents table?
0

Problem is fixed, issue with a broken save file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.