如何在使用MySQL的Ruby on Rails迁移中处理太长的索引名称? [英] How do I handle too long index names in a Ruby on Rails migration with MySQL?

查看:139
本文介绍了如何在使用MySQL的Ruby on Rails迁移中处理太长的索引名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加一个唯一索引,该索引是从四个关联表(用户大学 subject_names )的外键创建的, subject_types ):

I am trying to add an unique index that gets created from the foreign keys of four associated tables (users, universities, subject_names, subject_types):

add_index :studies, ["user_id", "university_id", \
          "subject_name_id", "subject_type_id"],
          :unique => true

MySQL对索引名称的限制导致迁移停止。以下是错误消息:

MySQL's limitation for the index name causes the migration to stop. Here is the error message:


表'研究'上的索引名称'index_studies_on_user_id_and_university_id_and_subject_name_id_and_subject_type_id'太长;限制为64个字符

Index name 'index_studies_on_user_id_and_university_id_and_subject_name_id_and_subject_type_id' on table 'studies' is too long; the limit is 64 characters

我该如何处理?我可以使用别名吗?

How can I handle this? Can I use an alias?

推荐答案

使用:

add_index :studies, ["user_id", "university_id", \
          "subject_name_id", "subject_type_id"], 
          :unique => true, :name => 'my_index'

更多信息请参见 add_index

More information is in add_index.

这篇关于如何在使用MySQL的Ruby on Rails迁移中处理太长的索引名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆