开发者

Ruby On Rails Migration

开发者 https://www.devze.com 2023-02-04 22:30 出处:网络
I have seen two different ways of migrating a database.Which one is the proper way to do it in Rails 3?

I have seen two different ways of migrating a database. Which one is the proper way to do it in 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

Thank You!


t.string :title is just a shortcut for t.column :title, :string

Both of them are ok, there is no discrimination. I'd normally prefer the short form, as it is more readable to me but it's just a matter of opinion.

0

精彩评论

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

关注公众号