diff --git a/alembic/versions/20250414_144046_ebe9468d_update_fruit.py b/alembic/versions/20250414_144046_ebe9468d_update_fruit.py index 42973df..c9ac9a6 100644 --- a/alembic/versions/20250414_144046_ebe9468d_update_fruit.py +++ b/alembic/versions/20250414_144046_ebe9468d_update_fruit.py @@ -13,7 +13,17 @@ branch_labels = None depends_on = None def upgrade(): - op.add_column('fruits', sa.Column('shape', sa.String(), nullable=False)) + # SQLite doesn't support adding NOT NULL columns without defaults + # We need to use batch operations for this + with op.batch_alter_table('fruits') as batch_op: + batch_op.add_column(sa.Column('shape', sa.String(), nullable=True)) + # Update existing rows with a default value + op.execute("UPDATE fruits SET shape = 'unknown' WHERE shape IS NULL") + # Now make the column NOT NULL + batch_op.alter_column('shape', + existing_type=sa.String(), + nullable=False) def downgrade(): - op.drop_column('fruits', 'shape') \ No newline at end of file + with op.batch_alter_table('fruits') as batch_op: + batch_op.drop_column('shape') \ No newline at end of file