中止更改后出现重复列名错误

发布于 2024-10-19 18:29:50 字数 675 浏览 1 评论 0原文

我创建了一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

就是爱搞怪 2024-10-26 18:29:50

你可以试试这个
转到此路径

/var/lib/mysql

并备份数据库(作为文件夹),

然后进入数据库文件夹并尝试删除表文件,

这可能有效

you can try this
go to this path

/var/lib/mysql

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

云裳 2024-10-26 18:29:50

看起来我不小心对错误的数据库运行了手动 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文