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

Alan Gauld alan.gauld at btinternet.com
Wed Sep 18 15:37:53 CEST 2013


On 18/09/13 09:10, memilanuk wrote:

> 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.
>
> line 57, in main
>      cur = g.db.execute('SELECT * FROM posts')
> OperationalError: no such table: posts
>
> def connect_db():
>      #return sqlite3.connect(app.config['DATABASE'])
>      return sqlite3.connect('fblog.db')

You may need to specify a relatie path rather than
just the filename.

> def main():
>      g.db = connect_db()
>      cur = g.db.execute('SELECT * FROM posts')

You are trying to execute on the database rather
than on a cursor. You need to create a cursor
first to hold your results.

Something like;

cur = g.db.cursor()
cur.execute(.....)

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list