相关疑难解决方法(0)

Rails迁移:self.up和self.down与change

看起来新的rails版本与self.up和self.down方法有"变化".

那么,当必须回滚迁移时会发生什么,它如何知道要执行的操作.我需要基于在线教程实现以下方法:

class AddImageToUsers < ActiveRecord::Migration
  def self.up
    add_column :users, :image_file_name, :string
    add_column :users, :image_content_type, :string
    add_column :users, :image_file_size, :integer
    add_column :users, :image_updated_at, :datetime
  end

  def self.down
    remove_column :users, :image_file_name, :string
    remove_column :users, :image_content_type, :string
    remove_column :users, :image_file_size, :integer
    remove_column :users, :image_updated_at, :datetime
  end    
end
Run Code Online (Sandbox Code Playgroud)

如何使用新的更改方法执行相同的操作?

migration ruby-on-rails

83
推荐指数
2
解决办法
4万
查看次数

标签 统计

migration ×1

ruby-on-rails ×1