Forums

"No such table" error?

Hi all,

I'm having a bit of trouble here and I was wondering if you could help please?

I'm getting the error:

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: user [SQL: 'INSERT INTO user (username, email) VALUES (?, ?)'] [parameters: ('admin', 'admin@example.com')]

using this code from the Flask-SQLAlchemy website:

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

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

me = User('admin', 'admin@example.com')
db.session.add(me)
db.session.commit()

I'm really confused because shouldn't it be automatically creating the table in the database? Where am I going wrong?

Any help would be greatly appreciated, thank you!

usually sqlalchemy requires you to run some sort of (one-off?) command to actually create the tables?