Add a default value to a column through a migration

后端 未结 7 1632
旧巷少年郎
旧巷少年郎 2020-11-28 02:16

How do I add a default value to a column that already exists through a migration?

All the documentation I can find shows you how to do it if the column doesn\'t alr

相关标签:
7条回答
  • 2020-11-28 02:34

    Here's how you should do it:

    change_column :users, :admin, :boolean, :default => false
    

    But some databases, like PostgreSQL, will not update the field for rows previously created, so make sure you update the field manaully on the migration too.

    0 讨论(0)
提交回复
热议问题