【问题标题】:Rails migration index name for partitioned database table is too long分区数据库表的 Rails 迁移索引名称太长
【发布时间】:2021-01-21 07:32:50
【问题描述】:

我的 Rails 应用程序的数据库被划分为多个分片,每个分片的partition_keytoyota_seller_account_id。 现在我想使用此迁移创建一个名为 agg_product_summary_breakdowns 的表:

class CreateAggProductSummaryBreakdowns < ActiveRecord::Migration[5.2]
  def change
    create_table :agg_product_summary_breakdowns, partition_key: :toyota_seller_account_id do |t|
      t.references :toyota_seller_account, null: false
      t.date :summary_date, null: false
      t.timestamps
    end
  end

  def down
    drop_table :agg_product_summary_breakdowns
  end
end

现在 Rails 将自动在 toyota_seller_account_id 上创建一个名为 index_agg_product_summary_breakdowns_on_toyota_seller_account_id 的索引,因为它是分区键。

但是,我会遇到这个错误:

ArgumentError: Index name 'index_agg_product_summary_breakdowns_on_toyota_seller_account_id' on table 'agg_product_summary_breakdowns' is too long; the limit is 63 characters。不幸的是,它只有 64 个字符长(比允许的长 1 个字符)。

我想保持表名不变,即agg_product_summary_breakdowns,并且分区键也不能更改。有没有办法覆盖我不知道的索引名称?

谢谢!

【问题讨论】:

    标签: ruby-on-rails indexing activerecord migration sharding


    【解决方案1】:

    只需更改索引的名称。尝试:

    t.references :toyota_seller_account, null: false, index: {name: :whatever_you_want}
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-18
    • 2013-03-04
    • 2021-09-06
    • 2012-09-21
    • 2019-02-14
    • 2017-11-05
    • 2020-04-10
    • 2019-02-13
    相关资源
    最近更新 更多