Reputation: 1277
I've been working through the Flask tutorial and am getting stuck.
In order to run the application, you have to import and run the init_db()
function through the Python shell to create the database.
The application worked fine, but now when I run it (I'm sure I didn't change anything!), I get the following error:
>>> from flaskr import init_db
>>> init_db()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "flaskr.py", line 39, in init_db
db.cursor().executescript(f.read())
sqlite3.OperationalError: near "subject": syntax error
I've copied and pasted the original documentation code several times, but it still spits out the same errors.
36 def init_db():
37 with closing(connect_db()) as db:
38 with app.open_resource('schema.sql', mode='r') as f:
39 db.cursor().executescript(f.read())
40 db.commit()
Upvotes: 0
Views: 2287
Reputation: 491
I have faced the same question, but I find that sqlite3 has restrict format requirement for script file. For the example in tutorial, the most common mistake may be that for the last item in your table declaration, no more comma is allowed in the end(I think some guys may want to add one for easy extension in the future ). Hope this help~
Upvotes: 1
Reputation: 28312
I think you need to indent it:
36 def init_db():
37 with closing(connect_db()) as db:
38 with app.open_resource('schema.sql', mode='r') as f:
39 db.cursor().executescript(f.read())
40 db.commit()
Upvotes: 1