Forbid null values
suggest changeTo 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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents