Mysql::Error: Duplicate entry

Posted by Shaliko on Stack Overflow See other posts from Stack Overflow or by Shaliko
Published on 2010-04-09T07:02:09Z Indexed on 2010/04/09 7:53 UTC
Read the original article Hit count: 434

Hi

I have a model

class Gift < ActiveRecord::Base
  validates_uniqueness_of :giver_id, :scope => :account_id
end

add_index(:gifts, [:account_id, :giver_id], :uniq => true)

Action

def create
  @gift= Gift.new(params[:gift])

  if @gift.save
    ...
  else
    ...
  end
end

In the "production" mode, I sometimes get an error

ActiveRecord::StatementInvalid: Mysql::Error: Duplicate entry '122394471958-50301499' for key 'index_gifts_on_account_id_and_user_id'

What the problem?

© Stack Overflow or respective owner

Mysql::Error: Duplicate entry

Posted by Shaliko on Stack Overflow See other posts from Stack Overflow or by Shaliko
Published on 2010-04-09T08:02:14Z Indexed on 2010/04/09 8:03 UTC
Read the original article Hit count: 434

Filed under:
|
|

Hi

I have a model

class Gift < ActiveRecord::Base
  validates_uniqueness_of :giver_id, :scope => :account_id
end

add_index(:gifts, [:account_id, :giver_id], :uniq => true)

Action

def create
  @gift= Gift.new(params[:gift])

  if @gift.save
    ...
  else
    ...
  end
end

In the "production" mode, I sometimes get an error

ActiveRecord::StatementInvalid: Mysql::Error: Duplicate entry '122394471958-50301499' for key 'index_gifts_on_account_id_and_giver_id'

What the problem?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about rails