flask_vote_app icon indicating copy to clipboard operation
flask_vote_app copied to clipboard

Operational Error

Open Cug-21 opened this issue 3 years ago • 0 comments

The error message is

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file

(Background on this error at: https://sqlalche.me/e/14/e3q8)

It says the error is on line fighters = Fighter.query.order_by('id').all()

My Run.py File is configured like this `import os from flask import Flask, render_template from flask_sqlalchemy import SQLAlchemy

app = Flask(name)

DATABASE_URL is by default

app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///tmp/test.db' db = SQLAlchemy(app)

#app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get'DATABASE_URL', 'sqlite:///tmp/test.db'

class User(db.Model): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(120), unique=True)

def __init__(self, email):
    self.email = email

def __repr__(self):
    return '<User %r>' % self.email

class Fighter(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(120), unique=True)

class Vote(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User', backref=db.backref('votes', lazy='dynamic')) fighter_id = db.Column(db.Integer, db.ForeignKey('fighter.id')) fighter = db.relationship('Fighter', backref=db.backref('votes', lazy='dynamic'))

@app.route('/', methods=['GET', 'POST']) def homepage(): fighters = Fighter.query.all() return render_template('index.html', fighters=fighters)

if name == 'main': app.run(debug=True)`

Cug-21 avatar Nov 01 '22 16:11 Cug-21