plentz / lol_dba

lol_dba is a small package of rake tasks that scan your application models and displays a list of columns that probably should be indexed. Also, it can generate .sql migration scripts.
1.59k stars 69 forks source link

Mysql2::Error: Table 'myapp_development.action_text_rich_texts' doesn't exist #146

Open timokleemann opened 1 year ago

timokleemann commented 1 year ago

I would love to use this gem but when I run rake db:find_indexes in my Rails 7 application I am getting:

Mysql2::Error: Table 'myapp_development.action_text_rich_texts' doesn't exist

Jellyfishboy commented 1 year ago

@timokleemann Run rails g migration CreateActionTextTables

Then add this to the migration:

  def change
    # Use Active Record's configured type for primary and foreign keys
    primary_key_type, foreign_key_type = primary_and_foreign_key_types

    create_table :action_text_rich_texts, id: primary_key_type do |t|
      t.string     :name, null: false
      t.text       :body, size: :long
      t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type

      t.timestamps

      t.index [ :record_type, :record_id, :name ], name: "index_action_text_rich_texts_uniqueness", unique: true
    end
  end

  private
  def primary_and_foreign_key_types
    config = Rails.configuration.generators
    setting = config.options[config.orm][:primary_key_type]
    primary_key_type = setting || :primary_key
    foreign_key_type = setting || :bigint
    [primary_key_type, foreign_key_type]
  end