[Tutor] flask/sqlite3 problem - 'OperationalError: no such table'?

Peter Otten __peter__ at web.de
Wed Sep 18 10:33:16 CEST 2013


memilanuk wrote:

> I'm working thru a Flask tutorial, and when I get to the portion for
> querying the database (sqlite3) for the existing posts, i.e. 'SELECT *
> FROM posts', I get an error that says there is no such table 'posts' in
> my database.  Yet I can query said db file from either the sqlite3
> command-line client, or from the python interactive interpreter, and run
> the same query and get the expected results.  I've looked at this 'til
> I'm about ready to go cross-eyed... I'm sure it must be something simple
> that I'm missing, but I can't seem to spot it.  Below is the tail end of
> the traceback error message, followed by the code from the file in
> question.  Any help would be much appreciated.

Sqlite3 (un)helpfully creates a new database if it doesn't find one. That 
may happen here if the current working directory differs from the one you 
are expecting.

I'd try specifying the complete path of the db, something like

def connect_db():
    return sqlite3.connect('/path/to/fblog.db')




More information about the Tutor mailing list