سؤال

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top