mysql - 在 Rails 中迁移期间重命名列时出错

标签 mysql ruby-on-rails migration

我尝试在 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

知道这可能来自哪里吗?

谢谢!

最佳答案

来自MySQL documentation

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/

相关文章:

ruby-on-rails - 等同于 Rails 的 Django 信号?

php - joomla 3 错误 : 0 Cannot open file for writing log

JavaScript 无法在 Rails 中运行

mysql - 将带有一些预定义值的行插入到 SQL 表中,一些来自另一个表以及连接字符串。

mysql本地导入数据基础知识

java - 如何用java检查mysql中的id是否已经存在

ruby-on-rails - "Correct"从后台(Resque)作业写入日志输出的方法?

node.js - 使用 sequelize 迁移将关联添加到非默认模式

iphone - Coredata手动迁移

mysql - 在 mySql 查询中访问转义的 JSON