Ruby on Rails ActiveRecord Migrations

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Parameters

Column typeDescription
:primary_keyPrimary key
:stringShorter string datatype. Allows limit option for maximum number of characters.
:textLonger amount of text. Allows limit option for maximum number of bytes.
:integerInteger. Allows limit option for maximum number of bytes.
:bigintLarger integer
:floatFloat
:decimalDecimal number with variable precision. Allows precision and scale options.
:numericAllows precision and scale options.
:datetimeDateTime object for dates/times.
:timeTime object for times.
:dateDate object for dates.
:binaryBinary data. Allows limit option for maximum number of bytes.
:booleanBoolean

Remarks

  • Most migration files live in db/migrate/ directory. They’re identified by a UTC timestamp at the beginning of their file name: YYYYMMDDHHMMSS_create_products.rb.

  • The rails generate command can be shortened to rails g.

  • If a :type is not passed to a field, it defaults to a string.



Got any Ruby on Rails Question?