I have an application (Rails 2.3.10) that is bombing out with the
following message:
A ActiveRecord::StatementInvalid occurred in confirmation#create:
Mysql::Error: Duplicate entry '185' for key 1: INSERT INTO
`confirmations` (`flags`, `quote_id`, `created_at`, `updated_at`,
`id`, `serialnum`) VALUES(31, 185, '2011-04-27 20:32:04', '2011-04-27
20:32:04', 185, 'lxpxno20500232dba41601')
/usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.10/lib/active_record/
connection_adapters/abstract_adapter.rb:227:in `log'
schema.rb shows:
create_table "confirmations", :force => true do |t|
t.integer "quote_id"
t.integer "flags"
t.datetime "created_at"
t.datetime "updated_at"
t.string "serialnum"
end
add_index "confirmations", ["quote_id"], :name =>
"index_confirmations_on_quote_id"
add_index "confirmations", ["serialnum"], :name =>
"index_confirmations_on_serialnum", :unique => true
the production database is mysql and on interrogation:
mysql> show index from confirmations;
+---------------+------------+----------------------------------
+--------------+-------------+-----------+-------------+----------
+--------+------+------------+---------+
| Table | Non_unique | Key_name |
Seq_in_index | Column_name | Collation | Cardinality | Sub_part |
Packed | Null | Index_type | Comment |
+---------------+------------+----------------------------------
+--------------+-------------+-----------+-------------+----------
+--------+------+------------+---------+
| confirmations | 0 | PRIMARY
| 1 | id | A | 26 | NULL |
NULL | | BTREE | |
| confirmations | 0 | index_confirmations_on_serialnum
| 1 | serialnum | A | 26 | NULL |
NULL | YES | BTREE | |
| confirmations | 1 | index_confirmations_on_quote_id
| 1 | quote_id | A | 26 | NULL |
NULL | YES | BTREE | |
+---------------+------------+----------------------------------
+--------------+-------------+-----------+-------------+----------
+--------+------+------------+---------+
3 rows in set (0.00 sec)
mysql>
Then when I mysqldump the table definition:
--
-- Table structure for table `confirmations`
--
CREATE TABLE `confirmations` (
`id` int(11) NOT NULL auto_increment,
`quote_id` int(11) default NULL,
`flags` int(11) default NULL,
`created_at` datetime default NULL,
`updated_at` datetime default NULL,
`serialnum` varchar(255) collate utf8_unicode_ci default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `index_confirmations_on_serialnum` (`serialnum`),
KEY `index_confirmations_on_quote_id` (`quote_id`)
) ENGINE=InnoDB AUTO_INCREMENT=189 DEFAULT CHARSET=utf8
COLLATE=utf8_unicode_ci;
SET character_set_client = @saved_cs_client;
Then when I go onto the mysql database I can do this:
mysql> insert into confirmations (quote_id) values(188);
Query OK, 1 row affected (0.01 sec)
mysql> select * from confirmations where quote_id = 188;
+-----+----------+-------+---------------------+---------------------
+-----------+
| id | quote_id | flags | created_at | updated_at |
serialnum |
+-----+----------+-------+---------------------+---------------------
+-----------+
| 188 | 188 | 4 | 2011-04-28 10:41:32 | 2011-04-28 10:41:32 |
10195323 |
| 189 | 188 | NULL | NULL | NULL |
NULL |
+-----+----------+-------+---------------------+---------------------
+-----------+
2 rows in set (0.00 sec)
So in some way the mysql adapter is reporting a statement invalid when
it shouldn't as far as I can tell.
Any ideas on where to start looking would be a great help.
O.
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.