1

I'm using Python to create a table through SQLite3, I'm getting told the table has been created in the interpreter but when looking at the table in cmd, there's no such table. Here's my code:

import sqlite3 as db

conn = db.connect('test.db')
cursor = conn.cursor()
cursor.execute("create table films(title text, year text, director text)")
print("tables added")

In the interpreter I get:

>>> ================================ RESTART ================================
>>> 
tables added

But when viewing the database through SQLite in cmd I get told:

Error: no such table: films

3 Answers 3

1

Make sure you run the script and interpreter in the same directory. Otherwise they referenece two different db files.

Sign up to request clarification or add additional context in comments.

Comments

0

Your code just works :-) I guess there's something wrong on how you're trying to access your table:

sucre:~ rlucia$ python sqltable.py
tables added
sucre:~ rlucia$ sqlite3 test.db
SQLite version 3.8.0.2 2013-09-03 17:11:13
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> PRAGMA table_info([films]);
0|title|text|0||0
1|year|text|0||0
2|director|text|0||0
sqlite> ^D
sucre:~ rlucia$ 

Comments

0

You are missing conn.commit(). Therefore your new table isn't saved and the SQL viewer cannot find the table.

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.