-1
私はフラスコtutorialに従っています。データベースを初期化しようとすると、step 5にエラーが発生します。 INIT_DBで、 db.cursor seei5.py ライン24()executescript(f.read()) sqlite3.OperationalError:私は、端末へflask initdb
入力するとフラスコエラーデータベースを活性化
が、これは私が取得エラーです。近く " 「ドロップ:構文エラー
私はこれは私のファイル構造であるのpython 3.6
を使用しています:
/seei5
/seei5
__init__.py
/static
/templates
seei5.py
schema.sql
setup.py
MANIFEST.in
MANIFEST.in
graft seei5/templates
graft seei5/static
include seei5/schema.sql
schema.sql
drop table if exists books;
create table books (
book_id integer,
title text,
PRIMARY KEY (book_id))
drop table if exists chapters;
create table chapters (
chapter_id integer,
chapter text,
book_id integer,
PRIMARY KEY (chapter_id),
FOREIGN KEY (book_id) REFERENCES books (book_id))
drop table if exists concepts;
create table concepts (
concepts_id integer,
concept text,
definition text,
chapter_id integer,
PRIMARY KEY (concepts_id),
FOREIGN KEY (chapter_id) REFERENCES chapters (chapter_id))
seei5.py
import os
import sqlite3
from flask import *
app = Flask(__name__)
app.config.from_object(__name__)
app.config.update(dict(
DATABASE=os.path.join(app.root_path, 'seei5.db'),
SECRET_KEY='development key',
USERNAME='admin',
PASSWORD='default'
))
app.config.from_envvar('SEEI5_SETTINGS', silent=True)
def connect_db():
rv = sqlite3.connect(app.config['DATABASE'])
rv.row_factory = sqlite3.Row
return rv
def init_db():
db = get_db()
with app.open_resource('schema.sql', mode='r') as f:
db.cursor().executescript(f.read())
db.commit()
@app.cli.command('initdb')
def initdb_command():
init_db()
print("Initialized the database.")
def get_db():
if not hasattr(g, 'sqlite_db'):
g.sqlite_db = connect_db()
return g.sqlite_db
@app.teardown_appcontext
def close_db(error):
if hasattr(g, 'sqlite_db'):
g.sqlite_db.close()