Forbid null values

suggest change

To forbid null values in your table columns, add the :null parameter to your migration, like this:

class AddPriceToProducts < ActiveRecord::Migration
  def change
    add_column :products, :price, :float, null: false
  end
end

add_column takes the table, the column name, then the type. ActiveRecord::Migration without a version number is the older style; Rails 5+ generators use ActiveRecord::Migration[5.0]. null: false does not rewrite rows that are already NULL. Backfill those values first, or the migration fails.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents