Database Migration Error
jscanning opened this issue · comments
I am attempting to integrate this ratyrate gem into my rails application. After installing the gem running rails g ratyrate [my user equivalent]
when I subsequently attempt to migrate the database, I continually get the following error:
$ rails db:migrate
== 20190508052745 CreateRates: migrating ======================================
-- create_table(:rates)
-> 0.0033s
-- add_index(:rates, :rater_id)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
Index name 'index_rates_on_rater_id' on table 'rates' already exists
...
The only way I've found to bypass this problem is to comment out or remove the add_index lines from the create_rates
and create_rating_caches
migrations, but I'm not sure if I would lose the functionality of the gem. Regardless I'm getting this issue from a fresh install.
just change it to the following and this will work:
class CreateRates < ActiveRecord::Migration[5.1]
def self.change
create_table :rates do |t|
t.belongs_to :rater
t.belongs_to :rateable, polymorphic: true
t.float :stars, null: false
t.string :dimension
t.timestamps
end
add_index :rates, [:rateable_id, :rateable_type]
end
end