我尝试在 Rails 中运行迁移来更改列的名称,但收到此错误:
Mysql::Error: Error on rename of './databasename/#sql-478_17b' to './databasename/zz_portal_users' (errno: 150): ALTER TABLE `zz_portal_users` CHANGE `user_id` `zz_user_id` int(11) DEFAULT NULL
这是我尝试运行的迁移:
class RenameUsersIdToZzUsersIdInZzPortalUsers < ActiveRecord::Migration
def self.up
rename_column :zz_portal_users, :user_id, :zz_user_id
end
def self.down
rename_column :zz_portal_users, :zz_user_id, :user_id
end
end
知道这可能来自哪里吗?
谢谢!
最佳答案
If ALTER TABLE dies with the following error, the problem may be that MySQL crashed during an earlier ALTER TABLE operation and there is an old table named A-xxx or B-xxx lying around:
Error on rename of './database/name.frm' to './database/B-xxx.frm' (Errcode: 17) In this case, go to the MySQL data directory and delete all files that have names starting with A- or B-. (You may want to move them elsewhere instead of deleting them.)
关于mysql - 在 Rails 中迁移期间重命名列时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4981136/