Lee.Longmore-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2009-Feb-18 17:53 UTC
Mysql::Error: Duplicate entry ''#'' for key # - Error with the test framework or ActiveRecord???
I am getting the following error during testing of my application (using the Rails testing framework): Mysql::Error: Duplicate entry ''140-2'' for key 1: INSERT INTO `accessibilities_member_entities` (`accessibility_id`, `member_entity_id`) VALUES (140, 2) The error occurs when I try to save two model objects where the model has the following HABTM association: has_and_belongs_to_many :member_entities, :class_name => "MemberEntity", :join_table => "accessibilities_member_entities", :foreign_key => "accessibility_id", :association_foreign_key => "member_entity_id" The two objects are distinct from each other and I would therefore expect ActiveRecord to generate a different value for accessibility_id in each row. I would expect member_entity_id to be the same value in each row. There is a compound primary key defined for the join table (accessibility_id + member_entity_id). The accessibility_id and member_entity_id database columns are defined as INT. My debugging has been fruitless and the objects seem fine before the save. Is this an error in the Rails testing framework or Active Record? I am using test fixtures etc to test my code. My application is running on Rails 2.2.2 and MySQL 5.0.51 (for Ubuntu). Any help/ideas much appreciated. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
jemminger
2009-Feb-18 22:00 UTC
Re: Mysql::Error: Duplicate entry ''#'' for key # - Error with the test framework or ActiveRecord???
Sounds like it''s trying to insert (140, 2) twice. Are your fixtures set up with unique ID''s for each fixture record? On Feb 18, 12:53 pm, "Lee.Longm...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org" <Lee.Longm...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> I am getting the following error during testing of my application > (using the Rails testing framework): > > Mysql::Error: Duplicate entry ''140-2'' for key 1: INSERT INTO > `accessibilities_member_entities` (`accessibility_id`, > `member_entity_id`) VALUES (140, 2) > > The error occurs when I try to save two model objects where the model > has the following HABTM association: > > has_and_belongs_to_many :member_entities, > :class_name => > "MemberEntity", > :join_table => > "accessibilities_member_entities", > :foreign_key => > "accessibility_id", > :association_foreign_key > => "member_entity_id" > > The two objects are distinct from each other and I would therefore > expect ActiveRecord to generate a different value for accessibility_id > in each row. I would expect member_entity_id to be the same value in > each row. There is a compound primary key defined for the join table > (accessibility_id + member_entity_id). The accessibility_id and > member_entity_id database columns are defined as INT. > > My debugging has been fruitless and the objects seem fine before the > save. Is this an error in the Rails testing framework or Active > Record? I am using test fixtures etc to test my code. > > My application is running on Rails 2.2.2 and MySQL 5.0.51 (for > Ubuntu). > > Any help/ideas much appreciated.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Lee.Longmore-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2009-Feb-19 07:10 UTC
Re: Mysql::Error: Duplicate entry ''#'' for key # - Error with the test framework or ActiveRecord???
Thanks for your reply... I have not created a fixture for one of the models that has the HABTM association or for the join table itself, although I do have a fixture for the model on the other side of the HABTM. Is it necessary to create fixtures for each? fyi, the model under test has methods whose job it is to populate the model''s table and the join table with reference data, and I am trying to test that these methods work. Hence I saw no need to create fixture data for the model and join table. On 18 Feb, 22:00, jemminger <jemmin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Sounds like it''s trying to insert (140, 2) twice. Are your fixtures > set up with unique ID''s for each fixture record? > > On Feb 18, 12:53 pm, "Lee.Longm...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org" > > <Lee.Longm...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > I am getting the following error during testing of my application > > (using the Rails testing framework): > > > Mysql::Error: Duplicate entry ''140-2'' for key 1: INSERT INTO > > `accessibilities_member_entities` (`accessibility_id`, > > `member_entity_id`) VALUES (140, 2) > > > The error occurs when I try to save two model objects where the model > > has the following HABTM association: > > > has_and_belongs_to_many :member_entities, > > :class_name => > > "MemberEntity", > > :join_table => > > "accessibilities_member_entities", > > :foreign_key => > > "accessibility_id", > > :association_foreign_key > > => "member_entity_id" > > > The two objects are distinct from each other and I would therefore > > expect ActiveRecord to generate a different value for accessibility_id > > in each row. I would expect member_entity_id to be the same value in > > each row. There is a compound primary key defined for the join table > > (accessibility_id + member_entity_id). The accessibility_id and > > member_entity_id database columns are defined as INT. > > > My debugging has been fruitless and the objects seem fine before the > > save. Is this an error in the Rails testing framework or Active > > Record? I am using test fixtures etc to test my code. > > > My application is running on Rails 2.2.2 and MySQL 5.0.51 (for > > Ubuntu). > > > Any help/ideas much appreciated.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
jemminger
2009-Feb-24 15:18 UTC
Re: Mysql::Error: Duplicate entry ''#'' for key # - Error with the test framework or ActiveRecord???
Can you post the code for both models and your test? On Feb 19, 2:10 am, "Lee.Longm...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org" <Lee.Longm...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Thanks for your reply... > > I have not created a fixture for one of the models that has the HABTM > association or for the join table itself, although I do have a fixture > for the model on the other side of the HABTM. Is it necessary to > create fixtures for each? > > fyi, the model under test has methods whose job it is to populate the > model''s table and the join table with reference data, and I am trying > to test that these methods work. Hence I saw no need to create fixture > data for the model and join table. > > On 18 Feb, 22:00, jemminger <jemmin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Sounds like it''s trying to insert (140, 2) twice. Are your fixtures > > set up with unique ID''s for each fixture record? > > > On Feb 18, 12:53 pm, "Lee.Longm...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org" > > > <Lee.Longm...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > I am getting the following error during testing of my application > > > (using the Rails testing framework): > > > > Mysql::Error: Duplicate entry ''140-2'' for key 1: INSERT INTO > > > `accessibilities_member_entities` (`accessibility_id`, > > > `member_entity_id`) VALUES (140, 2) > > > > The error occurs when I try to save two model objects where the model > > > has the following HABTM association: > > > > has_and_belongs_to_many :member_entities, > > > :class_name => > > > "MemberEntity", > > > :join_table => > > > "accessibilities_member_entities", > > > :foreign_key => > > > "accessibility_id", > > > :association_foreign_key > > > => "member_entity_id" > > > > The two objects are distinct from each other and I would therefore > > > expect ActiveRecord to generate a different value for accessibility_id > > > in each row. I would expect member_entity_id to be the same value in > > > each row. There is a compound primary key defined for the join table > > > (accessibility_id + member_entity_id). The accessibility_id and > > > member_entity_id database columns are defined as INT. > > > > My debugging has been fruitless and the objects seem fine before the > > > save. Is this an error in the Rails testing framework or Active > > > Record? I am using test fixtures etc to test my code. > > > > My application is running on Rails 2.2.2 and MySQL 5.0.51 (for > > > Ubuntu). > > > > Any help/ideas much appreciated.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---