Forums

Error: sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: user

Hi, I get this error, the table "user" exists in the database. As I found in the documentation I ran flask_app.py manually in the bash console to ensure "db.create_all()" is happening, however i can't get it to work. Here is my code:

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)

app.config.from_pyfile('config.py')
db = SQLAlchemy(app)
from views import *

if __name__ == '__main__':
    db.create_all()
    print('after db.create_all()')

models.py looks like this:

from flask_app import db
from flask_login import UserMixin

class User(UserMixin, db.Model):
    __tablename__ = "user"
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True)
    email = db.Column(db.String(50), unique=True)
    password = db.Column(db.String(80))

Can I check somehow if db.create_all() actually did something? Or can someone see where my code is wrong? Thanks in advance

Solved, in case anyone has the same issue:

In my case I did not put an underscore to the database URI in the config file. Therefore it defaulted to another database. After fixing the URI everything worked just fine like.