无法在rails 5上的ruby中回滚数据库迁移

时间:2017-03-19 22:53:51

标签: ruby-on-rails database-migration

enter image description here我有两次迁移!第一个创建表,第二个修改它!但是当我尝试回滚它时它不起作用!!我试图运行db:drop,create,migrate,db:reset它会迁移一切但回滚仍然无法正常工作

第一次迁移:

class CreateUsers < ActiveRecord::Migration[5.0]
  def up
    create_table :users do |t|
      t.string "first_name", :limit => 25
      t.string "last_name", :limit => 50
      t.string "email", :default => '', :null => false
      t.string "password", :limit => 40

      t.timestamps
    end
  end

  def down
    drop_table :users
  end
end

2nd migration:

class AlterUsers < ActiveRecord::Migration[5.0]
  def up
      rename_table("users", "admin_users")
      add_column('admin_users', 'username', :string, :limit => 25,
          :after => 'email')
      change_column('admin_users', 'email', :string, :limit => 100 )
      rename_column('admin_users', 'password', 'hashed_password' )
      add_index("admin_users", "username")
  end

  def down
      remove_index('admin_users', 'username')
      rename_column('admin_users', 'hashed_password', 'password')
      change_column('admin_users', 'email', :string, :default => '',
          :null => false)
      remove_column('admin_users', 'username')
      rename_column('admin_users', 'users')
  end
end

enter image description here

1 个答案:

答案 0 :(得分:0)

羽绒不应该

rename_column('admin_users', 'users')

应该是

rename_table('admin_users', 'users')