Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database Migration Error #169

Open
jscanning opened this issue May 8, 2019 · 1 comment
Open

Database Migration Error #169

jscanning opened this issue May 8, 2019 · 1 comment

Comments

@jscanning
Copy link

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.

@eller82
Copy link

eller82 commented Sep 27, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants