migration best practice

Hi, I'm wondering how to add a column with a notNull() restriction in a table that already contains records, I mean the records present before adding this column will automatically not respect the notnull restriction which will generate errors during migration, is there a good way to handle this case?
4 Replies
Atahualpa
Atahualpa3mo ago
What I’ve done is to modify the sql that is generated by the migration and add a filler value for all that are null. If you want non null I guess there is already a default value you had in mind ? That way by the time the sql file gets to the non null alter statement nothing is null Id love to know what other people do for this though 🙂
younes
younesOP3mo ago
thanks thats a nice pattern, could you provide the sql query thats fill all null column please ?
Atahualpa
Atahualpa3mo ago
That depends on your schema. You can probably google or ask AI but essentially it’s something like “update tablename set column = whatever where column is null
younes
younesOP3mo ago
thank you
Want results from more Discord servers?
Add your server