【问题标题】:how to add new column in ROR 3.0 once i completed rake db:migrate?完成 rake db:migrate 后如何在 ROR 3.0 中添加新列?
【发布时间】:2012-09-03 06:48:27
【问题描述】:

嗨,我是 Rails 3.0 上的新 ruby​​,我想知道如何创建新的第一列我迁移的文件

我使用

创建了迁移
rake db:migrate 

class CreateCheckings < ActiveRecord::Migration
  def change

    create_table :checkings do |t|

         t.string :phone, :limit => 20
          t.string  :email 
        t.integer  "country_id"
            t.string   "registration_via"
            t.string   "industry_type", :limit => 2
            t.boolean  "is_admin",              :default => false
            t.boolean  "is_account_blocked",    :default => false   

      t.timestamps
    end
  end
end

现在创建了新表以添加一些列,我该如何处理终端请帮助我。

【问题讨论】:

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


    【解决方案1】:

    运行 rails g migration add_column_name_to_table_name column_name:type 或 然后创建一个迁移rails g migration add_columns_to_tables

    def change
        add_column :table_name, :column_name, :type
    end
    

    参考http://guides.rubyonrails.org/migrations.html, http://api.rubyonrails.org/classes/ActiveRecord/Migration.html

    【讨论】:

      【解决方案2】:

      在终端

      rails g migration add_column_name_to_table_name column_name:type
      
      rails g migration add_columns_to_tables
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-11
        • 1970-01-01
        • 1970-01-01
        • 2022-10-25
        相关资源
        最近更新 更多