If you use flask_migrate to change the table name in your python code, be sure to do db migrate / db upgrade.
For example
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(64), index=True)
description = db.Column(db.String(120), index=True)
def __repr__(self):
return '<User %r>'%self.username
And after defining the table using Flask_SQLAlchemy,
class UserData(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(64), index=True)
description = db.Column(db.String(120), index=True)
def __repr__(self):
return '<User %r>'%self.username
If you change the table name (class name) like
flask db migrate
flask db upgrade
I have to
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) relation "user_data" does not exist
I get angry with "I don't have a table!" Just because you changed it in your python code doesn't mean that it implicitly changes it. It seems that you need to explicitly do flask db migrate / flask db upgrade. It looks like git.
Recommended Posts