# Undefined method "add\_reference"

**URL:** <https://www.ruby-forum.com/t/undefined-method-add-reference/153576>\
**Category:** Rails\
**Created:** [November 18, 2008, 11:17pm UTC](https://www.ruby-forum.com/t/undefined-method-add-reference/153576 "2008-11-18T23:17:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![asoto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/58956e/32.png) [@asoto](https://www.ruby-forum.com/u/asoto)\
**Post date:** [November 18, 2008, 11:17pm UTC](https://www.ruby-forum.com/t/undefined-method-add-reference/153576/1 "2008-11-18T23:17:45Z")

</div>

Greetings,

I try to add a foreign key in one of my rails migrations in the  
following way:

def self.up  
add\_reference :categories, :items  
end

This, strangely, leads to the following error during the migration:

– add\_reference(:categories, :items)  
rake aborted!  
undefined method `add\_reference’ for #

In the same way fails the code:

def self.up  
change\_table :categories do |t|  
t.references :items  
end  
end

I recently upgraded to Rails 2.1.2, if this is relevant to my case. Does  
anyone have any pointers on how to solve this problem?

Thanks in advance!
