Search code examples
pythonormsqlalchemypyramidalembic

How to remove default value in model and add alembic version?


I am having a pyramid application which uses sqlalchemy and alembic for databases and migrations. I need to remove default specifier from my model class and add a alembic version script to it.

Previously it was like this:

class TableOne(Base):
    __tablename__ = "table_one"
    id = Column(Integer, primary_key=True)
    field_one = Column(Boolean(name='field_one_bool'), default=False)

I removed the 'default=False' from the field_one variable and tried running:

alembic revision --autogenerate -m "remove default value for field_one"

The alembic version script was generated but all I got inside upgrade() and downgrade() methods were:

def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    pass
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    pass
    # ### end Alembic commands ###

Basically, I need to know what should I do in alembic script if i drop a 'default=False' from the model class.


Solution

  • The default of Column is handled entirely in Python, in contrast with server_default. Since removing it has no effect on the database, the generated migration script is empty. In other words you do not need a migration in this case.