【问题标题】:Ruby On Rails MigrationRuby On Rails 迁移
【发布时间】:2011-01-14 16:08:41
【问题描述】:

我见过两种迁移数据库的不同方法。在 Rails 3 中哪一种是正确的方法?

class CreateProducts < ActiveRecord::Migration
  def self.up
    create_table :products do |t|
      t.string :title

      t.timestamps
    end
  end

and

class CreateProducts < ActiveRecord::Migration
  def self.up
    create_table :products do |t|
      t.column :name, :string
      t.timestamps
    end
  end

谢谢!

【问题讨论】:

  • 第一个是默认的,看你脚手架的时候
  • 那么第二种有什么优势呢?
  • 第二个没有优势
  • 第二个只有一个缺点:它不如第一个紧凑。

标签: ruby-on-rails ruby database ruby-on-rails-3 migration


【解决方案1】:

t.string :title 只是t.column :title, :string 的快捷方式

两人都还好,没有歧视。我通常更喜欢简短的形式,因为它对我来说更具可读性,但这只是一个意见问题。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2015-04-09
  • 2019-12-24
  • 2012-11-11
  • 1970-01-01
  • 2010-12-29
  • 2015-09-09
  • 2011-04-29
  • 2013-11-03
相关资源
最近更新 更多