# How to define primary\_key at migrate

**URL:** <https://www.ruby-forum.com/t/how-to-define-primary-key-at-migrate/157748>\
**Category:** Rails\
**Created:** [January 14, 2009, 11:32pm UTC](https://www.ruby-forum.com/t/how-to-define-primary-key-at-migrate/157748 "2009-01-14T23:32:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hapkido\_kid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/7993a0/32.png) [@hapkido\_kid](https://www.ruby-forum.com/u/hapkido_kid)\
**Post date:** [January 14, 2009, 11:32pm UTC](https://www.ruby-forum.com/t/how-to-define-primary-key-at-migrate/157748/1 "2009-01-14T23:32:39Z")

</div>

Hi, I am a newbie.

I am wondering if anyone can show me how to define a primary\_key at  
migrate

create table (:zis, :primary\_key =\> ‘quwie’) do |t|  
t.column :quwie, :integer, :limit =\> 4

end

Is it the right way to do it?

---

<div class="post-metadata">

**Author:** ![hapkido\_kid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/7993a0/32.png) [@hapkido\_kid](https://www.ruby-forum.com/u/hapkido_kid)\
**Post date:** [January 15, 2009, 12:15am UTC](https://www.ruby-forum.com/t/how-to-define-primary-key-at-migrate/157748/2 "2009-01-15T00:15:36Z")

</div>

On Jan 14, 2009, at 2:32 PM, Zh Peng wrote:

> Is it the right way to do it?

Almost. Don’t specify the column… just the :primary\_key part…

Check the docs for more info.

[http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#M001654](http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#M001654)

---

<div class="post-metadata">

**Author:** ![hapkido\_kid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/7993a0/32.png) [@hapkido\_kid](https://www.ruby-forum.com/u/hapkido_kid)\
**Post date:** [January 15, 2009, 4:32pm UTC](https://www.ruby-forum.com/t/how-to-define-primary-key-at-migrate/157748/3 "2009-01-15T16:32:32Z")

</div>

Thank you.

Philip H. wrote:

> On Jan 14, 2009, at 2:32 PM, Zh Peng wrote:
> 
> > Is it the right way to do it?
> 
> Almost. Don’t specify the column… just the :primary\_key part…
> 
> Check the docs for more info.
> 
> [ActiveRecord::ConnectionAdapters::SchemaStatements](http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#M001654)
