views:

423

answers:

3

I'm a beginner at Ruby on Rails so I apologize if this is quite obvious, but I'm trying to learn how to write the database migration scripts and I'd like to change the following long_description to a text value instead of string:

class CreateArticles < ActiveRecord::Migration
  def self.up  
    create_table :articles do |t|
      t.column "short_description", :string
      t.column "long_description", :string
      t.timestamps
    end
  end
end

Any ideas how this is possible?

+2  A: 
class CreateArticles < ActiveRecord::Migration
  def self.up
    create_table :articles do |t|
      t.string :short_description
      t.text :long_description
      t.timestamps
    end
  end
  def self.down
    # don't forget the down method
  end
end

Also, don't forget the down method.

Migration types are listed here.

  • :string
  • :text
  • :integer
  • :float
  • :decimal
  • :datetime
  • :timestamp
  • :time
  • :date
  • :binary
  • :boolean
Simone Carletti
stray double quote at the end of the symbols on lines 4 and 5
MattMcKnight
Fixed, thank you.
Simone Carletti
A: 
create_table :articles do |t|
  t.column 'long_description', :text
  # ...
end
mtyaka
A: 

Set it to :text

Here's a good ref for you: Here

levi rosol