How do I get alembic to use a specified default value for a new column, without making it the server_default
?
Only the existing rows should receive this default value. New rows inserted after should still get server_default
.
I had a similar problem, I wanted a new column to be not nullable, which does not work for existing rows, of course. So I created the row without not null constraint first, filled the column with some custom python code and than altered the column (in the same migration) to have the constraint.
So you'd iterate over the existing objects, set the values according to the transient default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With