We have two columns which require to be declared as t.integer size(1) and size(2).
i.e. a max size of 1 (i.e upto 9) and max size of 2 (i.e upto 99). How should I declare this in my migration script.
We have two columns which require to be declared as t.integer size(1) and size(2).
Share
You should be able to set a :limit on your migration record. Check the documentation here — http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html#method-i-column
Ex:
add_column :my_tbl, :myint, :integer, :limit => 9
This will set a column length — in other words, it will only allow integers up to 9 digits long.
If you want to restrict the data input for this column, you’ll need to do validations in your model. Have a look at http://guides.rubyonrails.org/active_record_validations_callbacks.html#length