linking database when primary key is not id


I have 2 tables that I had created with migrations, but these are
based on existing database. So the automatically created id column is
not used. These tables have the following structure.

Table calls

Thanks a lot for your helpful answer.


I would recommend making a few changes to your DB schema if the tables
you posted are actually the ones you are using for your application. The
structure of the tables you posted opens you up to data integrity issues
and unpredictable application behaviour.

Thanks for the heads up. The clients.ivr_id is supposed to be a unique
field so I should have a unique constraint on it.

Ideally, since you mentioned that you won't be using the "id" column in
the clients table, you should delete it and define ivr_id as the primary
key for the clients table.

Is there a "rails" way to do this, ie via a migration. as far as I
know the id is created automatically, so there must be some way to
disable it and assign another column as the key field.