# Ruby Migration \>\> Foreign Keys

**URL:** <https://www.ruby-forum.com/t/ruby-migration-foreign-keys/109214>\
**Category:** Rails\
**Created:** [July 12, 2007, 1:25pm UTC](https://www.ruby-forum.com/t/ruby-migration-foreign-keys/109214 "2007-07-12T13:25:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gladiator](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ccd318/32.png) [@Gladiator](https://www.ruby-forum.com/u/Gladiator)\
**Post date:** [July 12, 2007, 1:25pm UTC](https://www.ruby-forum.com/t/ruby-migration-foreign-keys/109214/1 "2007-07-12T13:25:58Z")

</div>

I have two tables having many-to-many relationship.  
I created a join table containing the primary keys of both tables.

Can any body tell me how use  
Ruby migration for foreign keys…

Thanks in advance  
Satish

---

<div class="post-metadata">

**Author:** ![Gladiator](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ccd318/32.png) [@Gladiator](https://www.ruby-forum.com/u/Gladiator)\
**Post date:** [July 12, 2007, 2:48pm UTC](https://www.ruby-forum.com/t/ruby-migration-foreign-keys/109214/2 "2007-07-12T14:48:39Z")

</div>

Gladiator wrote:

> I have two tables having many-to-many relationship.  
> I created a join table containing the primary keys of both tables.
> 
> Can any body tell me how use  
> Ruby migration for foreign keys…
> 
> Thanks in advance  
> Satish

Don’t know what you mean. Do you mean something like this:

…  
create\_table :magazines\_readers, :id =\> false do |t|  
t.column :magazine\_id, :integer  
t.column :reader\_id, :integer  
end

(see “Rails Recipes” pag. 104)

for a many-to-many relation between magazines and readers (a magazine  
has many readers, a reader reads many magazines).

Roberto Gattinoni.
