I get the below error:
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: s_amodel [SQL: 'INSERT INTO s_amodel
from flask_wtf import Form
class SAForm(Form):
from app.app_and_db import db
class SAmodel(db.Model):
id = db.Column(db.Integer(), primary_key=True)
from app.app_and_db import app, db
from app.sa.forms import SAForm
from app.sa.models import SAmodel
@sa_blueprint.route('/sa/new', methods=['GET','POST'])
def new_sa():
form = SAForm(request.form, SAmodel)
if request.method=='POST' and form.validate():
model = SAmodel()
form.populate_obj(model)
db.session.add(model)
db.session.commit()
return redirect(url_for("sa.home_page"))
return render_template("new_sa.html", form=form)
SQLALCHEMY_DATABASE_URI = os.getenv('DATABASE_URL', 'sqlite:///app.sqlite')
This is what I have. The app.sqlite is created but it is 0 bytes. When I submit something using new_sa() function, I get the above error. Also how is it getting the table name "s_amodel"?
Any help would be greatly appreciated. Thanks a lot!
You're supposed to initialize/create the tables first. Please read the Creating the Database article in the official Flask documentation:
Such systems need a schema that tells them how to store that information. So before starting the server for the first time it’s important to create that schema.
Here's Flask's example of using a schema SQL script to create the database, tables, etc:
sqlite3 /tmp/flaskr.db < schema.sql
The recommended way is to use db.create_all()
within your app. For example, see: https://github.com/lily-mayfield/staticfuzz/blob/d2e54186f5639a06a5a796f0499a984ca8919ed7/staticfuzz.py#L403
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With