3

I'm running through the Flask tutorial for a simple blog/cms and I can't seem to open/create a database.

I'm currently on Windows 7, when I go to view the app I get a sqlite3.OperationalError OperationalError: unable to open database file error on the webpage. I've tried googling the issue but I haven't been able to fix it. I assume it has to do with that I'm using Windows. Can anyone help?

DATABASE = 'C:\Users\Brad\Documents\flaskr\flaskr.db'

def connect_db():
return sqlite3.connect(app.config['DATABASE'])

def init_db():
    with closing(connect_db()) as db:
       with app.open_resource('schema.sql') as f:
        db.cursor().executescript(f.read())
    db.commit()

1 Answer 1

7

Escape your string properly:

DATABASE = 'C:\\Users\\Brad\\Documents\\flaskr\\flaskr.db'
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, I didn't notice that.
@AllofHumanity: Windows understands forward slashes just fine, so you can use them as well. This will also make your code more compatible (well, besides the hard-coded parts, obviously). You might want to use os.path.join as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.