开发者

Ruby on Rails DB Migration Script Using Text instead of :string varchar

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 "lon开发者_如何学Gog_description", :string
      t.timestamps
    end
  end
end

Any ideas how this is possible?


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


create_table :articles do |t|
  t.column 'long_description', :text
  # ...
end


Set it to :text

Here's a good ref for you: Here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜