Rails 生成迁移 [英] Rails generate Migration

查看:33
本文介绍了Rails 生成迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个名为 Products 的迁移,我只是想向此迁移添加更多字符串,例如描述和产品类型.做这个的最好方式是什么?

I currently have migration called Products, and I simply want to add few more strings to this migration such as description and product type. What is the best way to do this?

class CreateProducts < ActiveRecord::Migration
  def change
    create_table :products do |t|
      t.string  :name
      t.decimal :price
      t.text    :description
      t.timestamps
    end
   end
 end

推荐答案

直接运行

rails g migration add_description_to_products description:string
rails g migration add_product_type_to_products product_type:string

然后运行

rake db:migrate

这篇关于Rails 生成迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆