Po tutorialu kolby z systemem Win 7, Python 2.7.3, virtualenv i siedzę w kroku 3: Tworzenie bazy danych http://flask.pocoo.org/docs/tutorial/dbinit/#tutorial-dbinitStuck na kolbie Tutorial krok 3
Such a schema can be created by piping the schema.sql file into the sqlite3 command as follows:
sqlite3 /tmp/flaskr.db < schema.sql
Jak uruchomić tego polecenia, ponieważ CMD < venv> powroty:
"sqlite3" is not recognized as internal or external command, operable program or batch file.
Czy to krok konieczny?
Folder Project 2 pliki schema.sql i flaskr.py.
schema.sql
drop table if exists entries;
create table entries (
id integer primary key autoincrement,
title string not null,
text string not null
);
flaskr.py
# all the imports
import sqlite3
from flask import Flask, request, session, g, redirect, url_for, \
abort, render_template, flash
from contextlib import closing
# configuration
DATABASE = '/tmp/flaskr.db'
DEBUG = True
SECRET_KEY = 'development key'
USERNAME = 'admin'
PASSWORD = 'default'
# create our little application :)
app = Flask(__name__)
app.config.from_object(__name__)
app.config.from_envvar('FLASKR_SETTINGS', silent=True)
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()
if __name__ == '__main__':
app.run()
<venv> python
>>> from flaskr import init_db
>>> init_db()
Trackeback <most recent call last>:
File "<stdin>", line 1, in <module>
File "flaskr.py", line 24, in init_db
with closing (connect_db()) as db:
File "flaskr.py", line 21, in connect_db
return sqlite3.connect(app.config['DATABASE'])
sqlite3.OperationalError: unable to open database.
Narzędzie wiersza poleceń nazywane jest "sqlite3.exe" w systemie Windows. –
"Wywołanie sqlite3.OperationalError" powodowane jest przez to, że SQLite nie może * zapisać * skonfigurowanego pliku bazy danych (tworzy go, jeśli jeszcze nie istnieje). –
Sciągnięte sqlite3.exe, sqlitie> sqlite3 /tmp/flaskr.db jakąkolwiek pomoc? –