I'm getting a rather strange syntax error in my schema.sql file.
The error is as follows:
File "/Users/user/Documents/GitProjects/FlaskApp/flaskr/db.py", line 88, in init_db_command init_db() File "/Users/user/Documents/GitProjects/FlaskApp/flaskr/db.py", line 80, in init_db db.executescript(f.read().decode("utf-8")) sqlite3.OperationalError: near "create": syntax error
My schema looks like this:
drop table if exists post;
drop table if exists post_user;
create table post_user (
user_id integer primary key autoincrement,
email text unique not null,
username text unique not null,
password text not null
);
create table post (
post_id integer primary key autoincrement,
author_id integer not null,
create timestamp not null default current_timestamp,
title text not null,
body text not null,
foreign key (author_id) references post_user (user_id)
);
And my python looks like this:
def init_db():
db = get_db()
with current_app.open_resource("schema.sql") as f:
db.executescript(f.read().decode("utf-8"))
And finally the directory:
root
|--db.py
|--schema.sql
instance
|-- project.sqlite
I'm using flask and sqlite3. And my troubleshooting steps have been the following:
1) Remove everything except the first line (this works)
2) Removed everything except the first two lines (this doesn't)
3) Remove the ./instance/project.sqlite file
4) Use an online validator This was especially interesting because this found that each individual command works. But as soon as I string two back-to-back it said the commands were invalid.
5) Double checked the sqlite documentation on dropping tables
6) Even went so far as to ensure my .vimrc was set to utf-8
I'm sure I've missed something small here but nothing seems to be working. Any help would be appreciated!