method
add_column
Ruby on Rails latest stable (v2.2.1)
-
4 notes -
Class: ActiveRecord::ConnectionAdapters::SchemaStatements
add_column(table_name, column_name, type, options = {})
public
Adds a new column to the named table. See TableDefinition#column for details of the options you can use.
Register or
log in
to add new notes.
neves -
August 19, 2008
dvdplm -
September 15, 2008
theill -
August 23, 2008
GavinLaking -
July 22, 2008
6 thanks
script/generate syntax
To add a post_id field to a comments table, run this:
script\generate migration add_post_id_to_comment post_id:integer
See that it´s not the table name(plural), but the model name(singular),<br /> and post_id:references, does not works like in create_table.
This is the generated migration:
class AddPostIdToComment < ActiveRecord::Migration def self.up add_column :comments, :post_id, :integer end def self.down remove_column :comments, :post_id end end
3 thanks
:null => false
To not allow a column to have a NULL value, pass :null => false. Seems silly, but that’s it.
3 thanks
3 thanks

