Stuck at Flask tutorial step 3 Stuck at Flask tutorial step 3 sqlite sqlite

Stuck at Flask tutorial step 3


You are confused between Windows and UNIX filesystems.

Find out where sqllite.exe file exists on the computer. lets say it is in C:\sqllite. Then you also need to determine where you will create the database file. /tmp/flaskr.db is for the UNIX filesystem. On windows, you should provide the exact path or in your current working directory. lets say it is C:\flasktutorial.

To be safe, you might want to create a blank flaskr.db file first.

Open a notepad and create the blank file at `C:\flasktutorial\flaskr.db`

Now you can run:

C:\sqllite\sqllite.exe C:\flasktutorial\flaskr.db < schema.sql

Also make sure that in your flaskr.py file, change the DATABASE to:

DATABASE = 'C:\flasktutorial\flaskr.db'


Did you activate virtualenv and installed flask?

flask should have sqlite3 by default. I got following error though:

 File "flaskr.py", line 26, in connect_db  return sqlite3.connect(app.config['DATABASE'])sqlite3.OperationalError: unable to open database file`

To fix that I had to do the following (in Windows):

  1. Change DATABASE = '/tmp/flaskr.db' to DATABASE = '.\\tmp\\flaskr.db'
  2. Create tmp folder in current folder (flaskr)
  3. Create an empty flaskr.db file in tmp

After that it's working for me.


As you can observe from the error logs, the error is coming while connecting DB

sqlite3.OperationalError: unable to open database.

And since this step failed for you,

sqlite3 /tmp/flaskr.db < schema.sql

You can easily interpret that this step is necessary.Now to solve this error, simply you have to install sqlite3, In ubuntu you can install sqlite3 as,

apt-get install sqlite3

After installation your program will work fine as expected.