如何在 mysql2+rails 3 中添加索引?
mysql2中如何添加索引?
与线: 执行“更改表 urlli_development.slugs 添加索引 slugs_sluggable_id(sluggable_id)” 一切正常。
使用行: add_index :slugs, :sluggable_id 我收到此“无效日期”错误。
问题是我必须添加以下行: add_index(:slugs, [:name, :sluggable_type, :sequence, :scope], :unique => true, :name => 'index_slugs_on_n_s_s_and_s')
上面的行不起作用。
我使用 Rails 3 和 mysql2,当我尝试迁移数据库时,出现“无效日期”错误。
你怎么做?
How do you add indexes in mysql2?
with line:
execute "alter table urli_development.slugs ADD INDEX slugs_sluggable_id(sluggable_id)"
everything works fine.
with line: add_index :slugs, :sluggable_id I get this 'Invalid date' error.
Problem is that I have to add following line:
add_index(:slugs, [:name, :sluggable_type, :sequence, :scope], :unique => true, :name => 'index_slugs_on_n_s_s_and_s')
Above line doesn't work.
I use Rails 3 and mysql2 and I get this 'Invalid date' error when I try to migrate database.
How do you do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我也遇到过这个问题,坦率地说,我还没有找到完整的“为什么”。但我确实想分享一些我刚刚发现的东西。
尝试通过排除“id”字段来创建表...add_index 将立即运行。
所以或者如果您希望在不同的迁移中执行此操作
实际上非常有趣 ->如果您切换这两行(add_index 和 add_column)...它不会工作!
I've had that problem too and to be quite frankly haven't got to a complete "why".But I do want to share something I just found out.
Try creating your table by excluding the "id" field....the add_index will run right away.So
Or if you wish to do it within a different migration
Actually is pretty interesting-> If you switch those two lines (add_index and add_column) ...IT WON'T WORK!
您遇到了 此错误。
(我假设你使用的是Windows)
您可以通过将新文件:///C:/../mysql/lib/opt/libmysql.dll 从 mysql 5.1 安装复制到 Ruby/bin 目录来解决该问题。
然后它又可以工作了!
you ran into this bug.
(I assume you're on Windows)
You can solve it by copying a fresh file:///C:/../mysql/lib/opt/libmysql.dll from your mysql 5.1 install to your Ruby/bin directory.
Then it works again!
您需要将“libmysql.ddl”重新复制并粘贴到 ruby 的 bin 文件夹中。
如果您的计算机上安装了 Mysql Workbench,则可以在 Mysql Workbench 的文件夹中获取它,或者从其他来源获取它。
You need to copy and paste, "libmysql.ddl" anew into ruby's bin folder.
You can get it in the folder of Mysql Workbench if you have it installed in your machine or from alternative sources.
尝试使用以前版本的 mysql gem 而不是 mysql2...
我在两个不同的项目中遇到过这个错误两次,这在两种情况下都拯救了我的日子:)
还值得一提的是,在 Ubuntu 中使用 mysql2 时,add_index 不会造成任何问题。我想这只是 Windows 的问题。
Try using a previous version of the mysql gem instead of mysql2...
I've run into this bug twice, in two different projects and this saved my day in both cases :)
It's also worth mentioning that add_index causes no trouble at all using mysql2 in Ubuntu. I guess this is a windows only issue.