I'm learning sqlite3 in python with this tutorial http://zetcode.com/db/sqlitepythontutorial/. I started "Inserting data" chapter. I ran this code:
import sqlite3 as lite
import sys
con = lite.connect('test.db')
with con:
cur = con.cursor()
cur.execute("CREATE TABLE Cars(Id INT, Name TEXT, Price INT)")
cur.execute("INSERT INTO Cars VALUES(1,'Audi',52642)")
cur.execute("INSERT INTO Cars VALUES(2,'Mercedes',57127)")
cur.execute("INSERT INTO Cars VALUES(3,'Skoda',9000)")
cur.execute("INSERT INTO Cars VALUES(4,'Volvo',29000)")
cur.execute("INSERT INTO Cars VALUES(5,'Bentley',350000)")
cur.execute("INSERT INTO Cars VALUES(6,'Citroen',21000)")
cur.execute("INSERT INTO Cars VALUES(7,'Hummer',41400)")
cur.execute("INSERT INTO Cars VALUES(8,'Volkswagen',21600)")
Then I made this in OS X terminal:
sqlite> .mode column
sqlite> .headers on
sqlite> SELECT * FROM Cars;
And this happened:
Error: no such table: Cars
I don't know why. Test.db and the script are in the same direction. I was searching for this problem and I only found solutions that I don't understand.
cur.execute("DROP TABLE IF EXISTS Cars")beforeCREATE TABLEsqlite3 test.dbor if you just ransqlite3that you first.open test.db.