Forum: Ruby on Rails how to use set_primary_key?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
47df9cfb356c3ee0523cc3571b169730?d=identicon&s=25 Kenneth McDonald (Guest)
on 2008-12-22 22:52
(Received via mailing list)
We are trying to use set_primary_key to cause an existing rails db to
use a different primary key. This works find for accessing existing
data, but gives an error when we try to add a new record, as it seems
to still be accessing the record by the default id field at that
point. Are there other changes we need to make to get an alternate
primary key working?

04952a6ee948f345e9c3727850d09a1b?d=identicon&s=25 Dejan Dimic (Guest)
on 2008-12-22 23:25
(Received via mailing list)
I have used the set_primary_key with some 3rd party propriety
databases with no issues you describe.

Could you give us some more information (table structure and such) to
be able to help you adequately.

On Dec 22, 10:51 pm, Kenneth McDonald
47df9cfb356c3ee0523cc3571b169730?d=identicon&s=25 Kenneth McDonald (Guest)
on 2008-12-22 23:34
(Received via mailing list)
I think the problem is likely that the "old" primary key in the
database is still the "id" field that rails generates and uses by
default, and we can't change that since (for the time being, our needs
being modest) we're using sqlite. We want to use a field called "rmr",
basically an identification number, as the primary key, but this
became obvious only after we'd created and started populating the

Does Rails interrogate the database to find out which column is the
primary key?

10f7e00c1c5c60e2173995eb16f4ffc7?d=identicon&s=25 pepe (Guest)
on 2008-12-24 05:11
(Received via mailing list)
I think I read somewhere that when creating a new record you still
have to reference the field as 'id' (id=value) or it will not work.
It's worth the try.


On Dec 22, 5:33 pm, Kenneth McDonald
This topic is locked and can not be replied to.