Ruby on Rails: How do I add a not null constraint to an existing column using a migration? Ruby on Rails: How do I add a not null constraint to an existing column using a migration? ruby-on-rails ruby-on-rails

Ruby on Rails: How do I add a not null constraint to an existing column using a migration?


You can also use change_column_null:

change_column_null :table_name, :column_name, false


1) FIRST: Add column with default value

2) THEN: Remove default value

add_column :orders, :items, :integer, null: false, default: 0change_column :orders, :items, :integer, default: nil