Skip to content
This repository has been archived by the owner on Nov 13, 2021. It is now read-only.

duplicate key value violates unique constraint "index_rs_evaluations_on_reputation_name_and_source_and_target" #86

Open
thebravoman opened this issue Sep 28, 2015 · 0 comments

Comments

@thebravoman
Copy link

The following error occurs on postgre running on heroku.

PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_rs_evaluations_on_reputation_name_and_source_and_target"
DETAIL: Key (reputation_name, source_id, source_type, target_id, target_type)=(watched_points, 135, Episode, 3774, User) already exists.
: INSERT INTO "rs_evaluations" ("created_at", "data", "reputation_name", "source_id", "source_type", "target_id", "target_type", "updated_at", "value") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING "id"
app/models/episode.rb:70:in `block in update_watched_points'

This is the code of the method being called:

def update_watched_points percentage, user
    to_be_given = calculate_some_value
    ActiveRecord::Base.transaction do
    current_points = self.evaluation_by :watched_points, user
        current_points = current_points.to_f
        if current_points < to_be_given
            user.add_or_update_evaluation :watched_points, to_be_given, self
            self.add_or_update_evaluation :watched_points, to_be_given, user
        end
    end
end

Do you know what might be causing it?

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

No branches or pull requests

1 participant