Update the Data model
-
14-11-2019 - |
题
I have Data Model (class) for example looking like this:
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(20), unique=True)
password = db.Column(db.String(30))
I have a lot of records in this table now and I want to add a field, for example to save the email address.
I have searched the documentation and have not found a recommended way to do this. I have updated my MySql manually and added the field to the model and works most of the time if I declare the fields correctly.
Is there a "Best Practice" how to do this? Does SQLAlchemy have built in support to make updates to the table definition?
解决方案
Short answer is "No".
But check out alembic.
不隶属于 StackOverflow