中止更改后出现重复列名错误
我创建了一个 Rails 数据库迁移来向数据库中的表添加一个新列,但在我注意到它花费的时间比预期长得多(15 分钟以上)后,我手动终止了运行迁移的 ruby 进程。然后我意识到,由于表中的数据量,运行时并没有异常,所以我尝试再次启动它。现在我收到错误:
Mysql::Error: Duplicate column name 'new_column': ALTER TABLE `table_name` ADD `new_column` varchar(255)
但是,当我手动进入 MySQL 时,desc table_name
显示该列不存在,并尝试手动删除它(alter table table_name drop new_column
code>) 告诉我:
ERROR 1091 (42000): Can't DROP 'new_column'; check that column/key exists
看起来中止初始添加过程会导致事情进入不一致的状态。我需要做什么来解决这个问题?
编辑:我尝试手动添加(准确复制上面错误中的 DDL),然后在 MySQL 提示符下删除该列,两者都工作正常,但是 rake db:migrate
继续给我上面的错误。
I created a Rails database migration to add a new column to a table in my database, but after I noticed it was taking much longer than expected (15 minutes plus), I manually killed the ruby process running the migration. Then I realized that the runtime wasn't out of the ordinary because of the amount of data in the table, so I tried started it again. Now I get the error:
Mysql::Error: Duplicate column name 'new_column': ALTER TABLE `table_name` ADD `new_column` varchar(255)
However, when I manually go into MySQL, desc table_name
shows that the column doesn't exist, and trying to drop it manually (alter table table_name drop new_column
) tells me:
ERROR 1091 (42000): Can't DROP 'new_column'; check that column/key exists
It looks like aborting the initial add process caused things to get into an inconsistent state. What do I need to do to resolve this?
Edit: I tried manually adding (copying exactly the DDL from the error above), then dropping the column at the MySQL prompt, and both worked fine, but rake db:migrate
continues to give me the error above.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以试试这个
转到此路径
并备份数据库(作为文件夹),
然后进入数据库文件夹并尝试删除表文件,
这可能有效
you can try this
go to this path
and take a backup of your database (as a folder)
then go inside the database folder and try to delete the table file
this maybe work
看起来我不小心对错误的数据库运行了手动 MySQL 命令(我没有切换到数据库的“开发”版本)。使用正确的数据库,我能够手动删除有问题的列。
It looks like I was accidentally running the manual MySQL commands against the wrong database (I wasn't switching to the "development" version of the database). Using the correct database, I was able to manually remove the offending column.