gpt4 book ai didi

sql - 索引名称太长 attachinary/postgresql

转载 作者:行者123 更新时间:2023-11-29 12:55:25 24 4
gpt4 key购买 nike

在为 Attachinary 安装 ruby​​ gem 并尝试运行 db:migrate 后,我一直收到此错误:

Index name 'index_attachinary_files_on_attachinariable_type_and_attachinariable_id' on table 'attachinary_files' is too long; the limit is 63 characters

我一直在搜索和寻找解决方案,当然听说过为索引命名以避免生成的索引,但它似乎没有用。实际上已经有一个名称字段说:

'name: by_scoped_parent'

这是我的迁移文件中的完整行:

add_index :attachinary_files, [:attachinariable_type, :attachinariable_id, :scope], name: 'by_scoped_parent'

迁移文件的内容如下:

class CreateAttachinaryTables < ActiveRecord::Migration[5.1]
def change
create_table :attachinary_files do |t|
t.references :attachinariable, polymorphic: true
t.string :scope

t.string :public_id
t.string :version
t.integer :width
t.integer :height
t.string :format
t.string :resource_type
t.timestamps
end

add_index :attachinary_files, [:attachinariable_type, :attachinariable_id, :scope], name: 'by_scoped_parent'
end
end

注意:我的db/migrate 文件夹中没有任何doublon。最后的迁移文件非常顺利。

我目前正在学习 Rails,所以如果这是一个愚蠢的问题,我希望有人能帮助和原谅我😇。

提前致谢!

最佳答案

由于迁移中的这一行,您收到错误:

t.references :attachinariable, polymorphic: true

默认索引为真。如果你不想要这个索引(这似乎是你稍后在索引中添加范围的情况)那么 make index: false:

t.references :attachinariable, polymorphic: true, index: false

或者添加一个名字:

t.references :attachinariable, polymorphic: true, index: {name: 'name of your choice here'}

关于sql - 索引名称太长 attachinary/postgresql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44555182/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com