Имя индекса слишком длинное - Rails 3
Я пытаюсь запустить эту миграцию:
class RemoveClientFromSalesteam < ActiveRecord::Migration
change_table :sales_teams do |t|
t.remove :client_id
end
end
Это ошибка, которую я получаю:
rake db:migrate
-- change_table(:sales_teams)
rake aborted!
An error has occurred, this and all later migrations canceled:
Index name 'temp_index_altered_sales_teams_on_client_priority_and_personal_priority' on table 'altered_sales_teams' is too long; the limit is 64 characters
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Это то, что мой schema.rb
похоже:
create_table "sales_teams", :force => true do |t|
t.string "name"
t.integer "firm_id"
t.boolean "client_priority"
t.boolean "personal_priority"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "client_id"
end
add_index "sales_teams", ["client_id"], :name => "index_sales_teams_on_client_id"
add_index "sales_teams", ["client_priority", "personal_priority"], :name => "index_sales_teams_on_client_priority_and_personal_priority"
add_index "sales_teams", ["name", "firm_id"], :name => "index_sales_teams_on_name_and_firm_id"
Мысли?
Благодарю.
1 ответ
Решение
Удалите индекс, удалите столбец, а затем снова добавьте индекс:
def up
remove_index :sales_teams, :column => [ :client_priority, :personal_priority ]
remove_column :sales_teams, :client_id
add_index :sales_teams, [ :client_priority, :personal_priority ]
end
Я предполагаю, что вы используете SQLite, большинство баз данных поддерживают реальные операции ALTER TABLE для удаления столбцов, но SQLite заставляет вас копировать таблицу (и индексы), отбрасывать таблицу и копировать все обратно; Драйвер Rails SQLite позаботится об этом за кулисами, но, видимо, не знает об ограничении длины идентификатора.
Вы также можете указать свои собственные имена индексов, используя :name
возможность add_index
а также remove_index
если необходимо.