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
答案 0 :(得分:0)
羽绒不应该
rename_column('admin_users', 'users')
应该是
rename_table('admin_users', 'users')