I have some model code that runs fine in development environment but
fails in the test environment.
In test, the code always fails at the same point with:
Mysql::Error: Duplicate entry ‘5-17’ for key ‘PRIMARY’: INSERT INTO
VALUES (17, 5) [0m
accessibilities_namespaces is a join table for HABTM relationships.
My logging suggests that ActiveRecord tries to insert the same record
twice when run in test (but only in test!) which would explain the
above error. I am sure that the code does not try to create the same
record twice and in any case it runs fine in development mode.
I have tried running the code using ‘script/console test’ and it fails
here also. Though it does not fail when run in ‘script/console
I suspect the problem does not lie with MySQL or ActiveRecord, but
something to do with the differences between running in development vs
Any thoughts appreciated. I’m baffled by this.