ruby-on-rails – migrations:t.references不允许指定索引名称
发布时间:2020-12-16 20:16:15 所属栏目:百科 来源:网络整理
导读:迁移中有以下几个: create_table :model_with_a_long_name do |t| t.references :other_model_with_an_equally_long_name,index: trueend 这会产生一个索引,其长度不能超过Postgres. 有没有办法手动指定索引名称(不分开添加整数列和索引)? 类似以下内容:
迁移中有以下几个:
create_table :model_with_a_long_name do |t| t.references :other_model_with_an_equally_long_name,index: true end 这会产生一个索引,其长度不能超过Postgres. 有没有办法手动指定索引名称(不分开添加整数列和索引)? 类似以下内容: create_table :model_with_a_long_name do |t| t.references :other_model_with_an_equally_long_name,index: true,index_name: 'model_and_other' end ? 解决方法
根据
Rails code for
references ,您可以这样做,为索引提供一个Hash选项,您需要调用的名称:name,so:
t.references :my_field,index: { name: 'my_index_name' } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- OSC 第 80 期高手问答精粹 —— React Native
- VB 陈伟视频总结
- 如何使用参数和reducer访问来调用redux动作?
- c – 我什么时候应该更喜欢`shared_ptr`到`make_shared`?
- ruby-on-rails – 如何使用Nokogiri和at_css获取img src
- ruby-on-rails – 可以属于多个其他对象的对象的模型设计?
- PostgreSQL9.0新特性介绍: alter default privileges,解决
- c – 了解C4673编译器警告
- Oracle 11g新特性direct path read引发的系统停运故障诊断处
- 是否需要在根元素中声明XML命名空间以便通过XPath查询进行匹