I've have searched through and tried every solution to this problem that I could find I am still having issues with creating the database in the flask tutorial:
http://flask.pocoo.org/docs/0.10/tutorial/dbinit/#tutorial-dbinit
The previous stackoverflow answers to this question centered around changing the path in DATABASE = ... or adding the actual flaskr.db file to the project file (although I am under the impression that sqlite3 should generate it automatically)
I'm using Cloud9 - which runs on ubuntu - so the original /tmp/flaskr.db path should work, yet it does not.
The contents of my project are:
/Flaskr
/static
/templates
flaskr.db
flaskr.py
schema.sql
The contents of flaskr.py:
# all the imports
import sqlite3
from contextlib import closing
from flask import Flask, request, session, g, redirect, url_for, \
abort, render_template, flash
app = Flask(__name__)
app.config.from_envvar('FLASKR_SETTINGS', silent=True)
DATABASE = '/tmp/flaskr.db'
DEBUG = True
SECRET_KEY = 'development key'
USERNAME = 'admin'
PASSWORD = 'default'
def connect_db():
return sqlite3.connect(app.config['DATABASE'])
def init_db():
with closing(connect_db()) as db:
with app.open_resource('schema.sql', mode='r') as f:
db.cursor().executescript(f.read())
db.commit()
if __name__ == '__main__':
app.run()
For DATABASE = '' , I have also tried entering direct path:
DATABASE = '/home/ubuntu/workspace/flaskr/flaskr.db'
and (yes, I realize these are the same thing)
DATABASE = '/flaskr/flaskr.db'
I would also like to note that the flaskr.db file under the flaskr project was not originally there - but I added while I was troubleshooting to see if I could provide it's direct path.
The error I get is:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "flaskr.py", line 28, in init_db
with closing(connect_db()) as db:
File "flaskr.py", line 25, in connect_db
return sqlite3.connect(app.config['DATABASE'])
KeyError: 'DATABASE'
Again, I'm using Cloud9 runs on a Unix OS