# HABTM Duplicate entry error

**URL:** <https://www.ruby-forum.com/t/habtm-duplicate-entry-error/164306>\
**Category:** Rails\
**Created:** [March 31, 2009, 1:29am UTC](https://www.ruby-forum.com/t/habtm-duplicate-entry-error/164306 "2009-03-31T01:29:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jables](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/58956e/32.png) [@Jables](https://www.ruby-forum.com/u/Jables)\
**Post date:** [March 31, 2009, 1:29am UTC](https://www.ruby-forum.com/t/habtm-duplicate-entry-error/164306/1 "2009-03-31T01:29:07Z")

</div>

I have a model OrderUser and a model Venue, both are related through a  
HABTM to relationship and the join table is order\_users\_venues with  
the two foreign keys venue\_id and order\_user\_id. I am trying to add  
venues to a user, it works fine if one user is doing this, but if  
another is it reinserts the same ids into the table and screws  
everything up:

Mysql::Error: Duplicate entry ‘1’ for key 1: INSERT INTO  
`order_users_venues` (`venue_id`, `id`, `order_user_id`) VALUES (1, 1,  
2)

This ‘1’ is entry 3 in the table.

Obviously I am not using HABTM correctly or am using it when it I  
shouldn’t be.

Please advise!

Thanks,  
John

---

<div class="post-metadata">

**Author:** ![Jables](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/58956e/32.png) [@Jables](https://www.ruby-forum.com/u/Jables)\
**Post date:** [March 31, 2009, 3:00am UTC](https://www.ruby-forum.com/t/habtm-duplicate-entry-error/164306/2 "2009-03-31T03:00:21Z")

</div>

Problem is solved!

FYI - in the migrations

create\_table :tablename, :id =\> false

:id =\> false being the key there
