# ActiveRecord Save Primary Key Issue

**URL:** <https://www.ruby-forum.com/t/activerecord-save-primary-key-issue/71005>\
**Category:** Rails\
**Created:** [October 4, 2006, 5:06pm UTC](https://www.ruby-forum.com/t/activerecord-save-primary-key-issue/71005 "2006-10-04T17:06:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ernie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/eb8c5e/32.png) [@ernie](https://www.ruby-forum.com/u/ernie)\
**Post date:** [October 4, 2006, 5:06pm UTC](https://www.ruby-forum.com/t/activerecord-save-primary-key-issue/71005/1 "2006-10-04T17:06:14Z")

</div>

Help!  
I’m trying to save a record in Rails to a table that does not have a  
primary key. Rails is trying to auto-increment the primary key for me -  
but there isn’t one, so it throws an exception. Does anyone know how to  
turn off auto-incrementing of primary keys - if at all possible?

Thanks,  
Ernie

---

<div class="post-metadata">

**Author:** ![ernie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/eb8c5e/32.png) [@ernie](https://www.ruby-forum.com/u/ernie)\
**Post date:** [October 4, 2006, 6:16pm UTC](https://www.ruby-forum.com/t/activerecord-save-primary-key-issue/71005/2 "2006-10-04T18:16:51Z")

</div>

Ernie wrote:

> Help!  
> I’m trying to save a record in Rails to a table that does not have a  
> primary key. Rails is trying to auto-increment the primary key for me -  
> but there isn’t one, so it throws an exception. Does anyone know how to  
> turn off auto-incrementing of primary keys - if at all possible?
> 
> Thanks,  
> Ernie

Anybody???

---

<div class="post-metadata">

**Author:** ![ernie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/eb8c5e/32.png) [@ernie](https://www.ruby-forum.com/u/ernie)\
**Post date:** [October 5, 2006, 12:47am UTC](https://www.ruby-forum.com/t/activerecord-save-primary-key-issue/71005/3 "2006-10-05T00:47:26Z")

</div>

On Wednesday 04 October 2006 12:16, Ernie wrote:

> > Help!  
> > I’m trying to save a record in Rails to a table that does not have a  
> > primary key. Rails is trying to auto-increment the primary key for me -  
> > but there isn’t one, so it throws an exception. Does anyone know how to  
> > turn off auto-incrementing of primary keys - if at all possible?
> > 
> > Thanks,  
> > Ernie
> 
> Anybody???

What good is a table that has no primary key? In 20 years of designing  
databases large and small I cannot recall a single case where it would  
have  
been appropriate having a table without primary key.

Just consider the following scenario: for some reason (eg programmatic  
error)  
an identical record is inserted twice. You want to get rid of one copy.  
Unless you use a backend that generates some sort of unique feature (eg  
OID  
in PostgreSQL) you will find that you can’t.

Horst

---

<div class="post-metadata">

**Author:** ![ernie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/eb8c5e/32.png) [@ernie](https://www.ruby-forum.com/u/ernie)\
**Post date:** [October 5, 2006, 6:41pm UTC](https://www.ruby-forum.com/t/activerecord-save-primary-key-issue/71005/4 "2006-10-05T18:41:12Z")

</div>

Oracle Applications does not use referential integrity amongst its  
tables, for one. The overhead for RI in some cases can be…excessive.  
Which is one thing, in an odd way, that probably _helps_ MySQL be a  
tolerable DBMS behind applications, despite its deficiencies and  
warts. Most web app developers seem to implement and enforce RI in  
their applications…

---

<div class="post-metadata">

**Author:** ![ernie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/eb8c5e/32.png) [@ernie](https://www.ruby-forum.com/u/ernie)\
**Post date:** [October 5, 2006, 4:43pm UTC](https://www.ruby-forum.com/t/activerecord-save-primary-key-issue/71005/5 "2006-10-05T16:43:46Z")

</div>

Horst H. wrote:

> On Wednesday 04 October 2006 12:16, Ernie wrote:
> 
> > > Help!  
> > > I’m trying to save a record in Rails to a table that does not have a  
> > > primary key. Rails is trying to auto-increment the primary key for me -  
> > > but there isn’t one, so it throws an exception. Does anyone know how to  
> > > turn off auto-incrementing of primary keys - if at all possible?
> > > 
> > > Thanks,  
> > > Ernie
> > 
> > Anybody???
> 
> What good is a table that has no primary key? In 20 years of designing  
> databases large and small I cannot recall a single case where it would  
> have  
> been appropriate having a table without primary key.
> 
> Just consider the following scenario: for some reason (eg programmatic  
> error)  
> an identical record is inserted twice. You want to get rid of one copy.  
> Unless you use a backend that generates some sort of unique feature (eg  
> OID  
> in PostgreSQL) you will find that you can’t.
> 
> Horst

I know I know…I completely agree with all of you. I’m working with a  
legacy db, and they want to try to stay away from modifying db that is  
in production.

Thanks again,  
Ernie
