# Alternate primary key for legacy data

**URL:** <https://www.ruby-forum.com/t/alternate-primary-key-for-legacy-data/186948>\
**Category:** Rails\
**Created:** [April 14, 2010, 8:52pm UTC](https://www.ruby-forum.com/t/alternate-primary-key-for-legacy-data/186948 "2010-04-14T20:52:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ben-v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecb155/32.png) [@ben-v](https://www.ruby-forum.com/u/ben-v)\
**Post date:** [April 14, 2010, 8:52pm UTC](https://www.ruby-forum.com/t/alternate-primary-key-for-legacy-data/186948/1 "2010-04-14T20:52:02Z")

</div>

I have a “journals” table (created with a rails migration but with “id”  
renamed to “id\_journal”) with auto-incrementing primary key  
“id\_journal”.

class Journal \< ActiveRecord::Base  
set\_primary\_key “id\_journal”  
end

Despite using set\_primary\_key in the Journal model, I get the following  
error:

Mysql::Error: Failed to read auto-increment value from storage engine:  
INSERT INTO `journals` (`jname`, `created_at`, `updated_at`,  
`has_full_text_online`, `iscomplete`, `publisher`, `flagged`, `issn`,  
`instance`, `link`, `subjects`) VALUES(‘Actas Dermo-SifiliogrÃ¡ficas  
(English Edition)’, ‘2010-04-14 04:27:42’, ‘2010-04-14 04:27:42’, NULL,  
0, ‘’, 0, ‘’, ‘SD-1’, ‘’, ‘’)

Is this an issue with ActiveRecord not recognizing the primary key, or  
an issue with how the database is setup? Everything worked fine when the  
field was named “id”.

Thanks in advance!

Ben

---

<div class="post-metadata">

**Author:** ![ben-v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecb155/32.png) [@ben-v](https://www.ruby-forum.com/u/ben-v)\
**Post date:** [April 14, 2010, 11:07pm UTC](https://www.ruby-forum.com/t/alternate-primary-key-for-legacy-data/186948/2 "2010-04-14T23:07:06Z")

</div>

No. set\_primary\_key should work. But looks like a mysql error.  
There looks like mysql unable to do auto-increment. Please search  
online regarding this mysql error.

Try in the Irb, setting up the primary key value explicitly.

Like,  
Journal.insert(:id\_journal=\>100, :jname=\>‘Actas Dermo-Sifiliográficas’)  
and see the result. If this is accepted, then, some issue with  
auto-increment.

Cheers  
Amala

On 14 April 2010 19:52, Ben V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> For more options, visit this group at [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

## –

Nandri(Thanks in Tamil),  
Amala S.
