In my model, I add a column like this:
deadline = db.Column(db.Date, default=date.max)
Then the migration script is generated automatically. In upgrade() the operation is like this:
op.add_column('posts', sa.Column('deadline', sa.Date(), nullable=True))
Although no 'default' parameter is assigned in add_column(...) function, I find it works well in my db when a new item is inserted, giving a default date of 9999/12/31.
That it what I want, but how does the script know the default value without any information in migration script?
The default is handled by the model, it is not part of the database schema. SQLAlchemy also supports server-side defaults, which are handled by the database. To use a server-side default use the server_default argument in the column declaration. I haven't checked, but the server-side defaults should be picked up by migration scripts.
Thanks.
Most helpful comment
Thanks.