0
点赞
收藏
分享

微信扫一扫

rails表增加列

简单聊育儿 2022-04-16 阅读 85

rails增加列

rails generate migration NAME [field[:type][:index] field[:type][:index]] [options]
bundle exec rake db:migrate

这将产生以下迁移:

class AddDetailsToUsers < ActiveRecord::Migration[5.0]
  def change
    add_column :users, :name, :string
    add_column :users, :salary, :decimal
    add_column :users, :email, :string
  end
end
在表增加created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
def change
  create_table :lines_sources do |t|
    t.datetime :created_at, null: false
  end
end
举报

相关推荐

0 条评论