# Non-autoincremented primary keys

**URL:** <https://www.ruby-forum.com/t/non-autoincremented-primary-keys/112447>\
**Category:** Rails\
**Created:** [August 19, 2007, 3:03am UTC](https://www.ruby-forum.com/t/non-autoincremented-primary-keys/112447 "2007-08-19T03:03:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shawn\_Page](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/47e85d/32.png) [@Shawn\_Page](https://www.ruby-forum.com/u/Shawn_Page)\
**Post date:** [August 19, 2007, 3:03am UTC](https://www.ruby-forum.com/t/non-autoincremented-primary-keys/112447/1 "2007-08-19T03:03:21Z")

</div>

Hi,

I am trying to populate a legacy table with a primary key of ‘id’, but  
the id is not auto-incremented (the id is currently populated with the  
results from another table that has an auto-incremented id).

I’m POSTing xml to a controller created by the scaffold\_resource  
generator  
e.g.:

echo ’  
  
2  
Tom  
’ | curl -X POST -H ‘Content-type: text/xml’ -d @-  
[http://localhost:3000/users](http://localhost:3000/users)

However, the id specified in the xml is not saved.

The development log shows the following parameters being received:

Parameters: {“user”=\>{“name”=\>“Dick”, “id”=\>“2”}, “action”=\>“create”,  
“controller”=\>“users”}

However, in users\_controller.create, I am having to explicitly set the  
id myself

@user = User.new(params[:user])  
@user.id = params[:user][:id]

Is there a better way to do this? A setting perhaps regarding a non-  
autoincremented primary key?

Thanks,  
Shawn
