Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jitensachdeva/f582f6e05313bc1699ac to your computer and use it in GitHub Desktop.

Select an option

Save jitensachdeva/f582f6e05313bc1699ac to your computer and use it in GitHub Desktop.

Rails Migration

http://guides.rubyonrails.org/migrations.html

Migrations methods:

  • add_column
  • add_index
  • change_column
  • change_table
  • create_table
  • drop_table
  • remove_column
  • remove_index
  • rename_column

Basic format YYYYMMDDHHMMSS_create_products.rb

Supported types

  • :binary
  • :boolean
  • :date
  • :datetime
  • :decimal
  • :float
  • :integer
  • :primary_key
  • :string
  • :text
  • :time
  • :timestamp especial type:
  • :references

Commands to create migrations

$ rails generate model Product name:string description:text
$ rails generate migration AddPartNumberToProducts part_number:string
$ rails generate migration RemovePartNumberFromProducts part_number:string
$ rails generate migration AddDetailsToProducts part_number:string price:decimal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment