Ruby on Rails数据库迁移脚本使用Text而不是:string varchar

时间:2009-11-23 15:03:09

标签: ruby-on-rails database migration

我是Ruby on Rails的初学者,所以我很抱歉,如果这很明显,但我正在尝试学习如何编写数据库迁移脚本,我想将以下long_description更改为文本值字符串:

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

任何想法如何可行?

3 个答案:

答案 0 :(得分:3)

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

另外,不要忘记down方法。

列出了迁移类型here

  • :字符串
  • :文本
  • :整数
  • :浮
  • :小数
  • :日期时间
  • :时间戳
  • :时间
  • :日期
  • :二进制
  • :布尔

答案 1 :(得分:0)

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

答案 2 :(得分:0)

将其设置为:text

这是一个很好的参考资料:Here