# Legacy database and rails with its auto incrementing primary key problems

**URL:** <https://www.ruby-forum.com/t/legacy-database-and-rails-with-its-auto-incrementing-primary-key-problems/142053>\
**Category:** Rails\
**Created:** [July 2, 2008, 11:56pm UTC](https://www.ruby-forum.com/t/legacy-database-and-rails-with-its-auto-incrementing-primary-key-problems/142053 "2008-07-02T23:56:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cinderedmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/74df32/32.png) [@cinderedmonkey](https://www.ruby-forum.com/u/cinderedmonkey)\
**Post date:** [July 2, 2008, 11:56pm UTC](https://www.ruby-forum.com/t/legacy-database-and-rails-with-its-auto-incrementing-primary-key-problems/142053/1 "2008-07-02T23:56:21Z")

</div>

I’m sorta stuck as to what to do.  
I’m porting a legacy database where the primary key were not auto  
incrementing fields.

An example

create\_table: components do |t|  
t.integer :componentid  
…  
end

and

create\_table: versions do |t|  
t.integer :versionid  
t.integer :componentid  
…  
end

The foreign key for table versions is componentid from table  
components.  
In MySQL, the primary key would be ‘id’, an auto incrementing field.  
I would have liked to make componentid in components my primary key  
but seems rails does not like non-auto incrementing primary keys…so  
the question becomes how do I create the key relationship?  
I would like to be make searches along the lines of  
version=components.versions.versionid or some such. Am I making any  
sense?

Thanks in advance,  
Hubert
