Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify the size of an integer in the migration script

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.

like image 901
Joe Avatar asked Dec 26 '22 14:12

Joe


1 Answers

Do you mean that the value in that column should be restricted to the range 1-99?

Having created an integer column you could add ActiveRecord validation to the model:

validates_numericality_of :field_name, :in => 1..99
like image 84
Chris Lewis Avatar answered Jan 29 '23 17:01

Chris Lewis