add_column
 
  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.
 theill -  
    August 23, 2008
 theill -  
    August 23, 2008 
    
   neves -  
    August 19, 2008
 neves -  
    August 19, 2008 
    
  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
 annaswims -  
    July  7, 2009
 annaswims -  
    July  7, 2009 
    
  Options
Available options are (none of these exists by default):
* :limit - Requests a maximum column length. This is number of characters for :string and :text columns and number of bytes for :binary and :integer columns. * :default - The column‘s default value. Use nil for NULL. * :null - Allows or disallows NULL values in the column. This option could have been named :null_allowed. * :precision - Specifies the precision for a :decimal column. * :scale - Specifies the scale for a :decimal column.
 dvdplm -  
    September 15, 2008
 dvdplm -  
    September 15, 2008 
    
  :null => false
To not allow a column to have a NULL value, pass :null => false. Seems silly, but that’s it.
 GavinLaking -  
    July 22, 2008
 GavinLaking -  
    July 22, 2008 
    
   bquorning -  
    February 25, 2010
 bquorning -  
    February 25, 2010 
    
  Redirect...
See ActiveRecord::ConnectionAdapters::TableDefinition#column for details of the options you can use.
 shadowfiend -  
    May 15, 2009
 shadowfiend -  
    May 15, 2009 
    
  script/generate can take table name
As far as I can tell script/generate will happily take the plural table name, at least in Rails 2.3.

 RSpec
RSpec Ruby on Rails
Ruby on Rails Ruby
Ruby 
   
   
   
    
     
   
    
    
     
   
   
    