Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alembic default value to be used in add_column

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.

like image 809
00500005 Avatar asked Apr 25 '16 00:04

00500005


1 Answers

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.

like image 197
Tim-Erwin Avatar answered Sep 19 '22 23:09

Tim-Erwin