You are here: Home Solidarrow Ruby on Rails Solidarrow Cheatsheets

* Rails Migrations Cheatsheet

Up and down methods, rake tasks, column mapping, loading fixtures, example migration file, all packed onto one A4 page for an easy at-a-glance reference. Updated for Rails 2.1

Column methods

add_column

Creates a new column on the specified table.

    add_column :table_name, :column_name, :column_type, {column_options}

{column_options}

:null

true or false

if false, the underlying column has a not null constraint added by the database engine

:limit

integer

set a limit on the size of the field

:default

string

set a default value for the column

:precision

integer

Specifies the precision for a :decimal column.

:scale

integer

Specifies the scale for a :decimal column.

change_column

Change the data type of the specified column

    change_column :table_name, :column_name, :new_column_type

rename_column

Renames the specified column.

    rename_column :table_name, :old_column_name, :new_column_name 

remove_column

Removes the specified column.

    remove_column :table_name, :column_name



 

 

> RELATED ARTICLE

* New in Rails 2.0: Sexy Migrations

A look at the new features and syntax available in migrations on Rails 2.0 > More

 

> RELATED ARTICLE

* Auto migrations

A brilliant plugin that makes changing your database schema even easier and faster. > More