Stuart Wade
2006-Aug-16 14:35 UTC
[Rails] mysterious ''duplicate entry'' database error when building table
hi, i tried posting this yesterday, but i never saw my message make it to the list so i suspect something went awry.. my rails app has some ''sync'' code where it connects to a remote db, grabs the records from a table, deletes all the records from a table which is a local copy, and then rebuild the table with the records fetched on the remote db.. it boggles the mind how a duplicate entry error can come up when the source database is confirmed to have no dups in it, the local table gets torn down completely, and rebuilt from scratch. the error only comes up every once in a while, so often the code runs fine.. here''s the code in question: begin #rescue block in event remote db is unreachable homelinks = Syncinventorydesc.find(:all) #fetch all records rescue end InventoryDescription.delete_all() #drop all records from local table for link in homelinks #for each record we fetched.. locallink = InventoryDescription.new() locallink.inventory_id = link.inventory_id locallink.description_id = link.description_id locallink.save! #insert into table end since it was just a duplicate entry (no loss of data) i just wrapped that save in a rescue block too. the mystery remains however.. what happened? thanks for the assistance! stuart
Possibly Parallel Threads
- duplicate entry mystery
- [retry] fixture_references: "Mysql::Error #HY000"? (fwd)
- Difference between mongrel and webrick handling request.request_uri
- Dedupping Has_many through, :unique=>true
- categories/recipes & books/descriptions - has_many vs has_one => id question