Reputation: 132
I'm using this tutorial for learning flask. In the second paragraph it says to use this command:
sqlite3 /tmp/flaskr.db < schema.sql
But I'm using Windows 8. What can I do instead of that command? This is my sql code:
drop table if exists entries;
create table entries (
id integer primary key autoincrement,
title text not null,
text text not null
);
Upvotes: 2
Views: 3879
Reputation: 5064
Just keep following the tutorial by adding the init_db method and running the following python script:
# all the imports
import sqlite3
from flask import Flask
from contextlib import closing
# configuration
DATABASE = './flaskr.db'
DEBUG = True
# create our little application :)
app = Flask(__name__)
app.config.from_object(__name__)
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()
def connect_db():
return sqlite3.connect(app.config['DATABASE'])
if __name__ == '__main__':
init_db()
#app.run()
to make it simple, database file flaskr.db will be created in the current directory and schema.sql is supposed to be there too ...
Upvotes: 2