# Use of guid values and foreign key constraints

**URL:** <https://www.ruby-forum.com/t/use-of-guid-values-and-foreign-key-constraints/127604>\
**Category:** Rails\
**Created:** [January 30, 2008, 7:25pm UTC](https://www.ruby-forum.com/t/use-of-guid-values-and-foreign-key-constraints/127604 "2008-01-30T19:25:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [January 30, 2008, 7:25pm UTC](https://www.ruby-forum.com/t/use-of-guid-values-and-foreign-key-constraints/127604/1 "2008-01-30T19:25:16Z")

</div>

# It is pretty easy to make primary keys a guid value by:

class CreateAccounts \< ActiveRecord::Migration  
def self.up  
create\_table(:accounts, :primary\_key =\> :guid) do |t|  
…

But I am unsure how to create the foreign key constraints to allow them  
to accept the guid values. Setting the column type fails (t.guid  
:account\_id), as it seems that guid an undefined method.

Setting the relational column to a string also causes a failure when  
creating the foreign key constraints.

Does anyone have any experience with this?

I see there is a plugin here, but I don’t know if this will fix the  
issue with the foreign keys.  
[http://wiki.rubyonrails.org/rails/pages/Uses+Guid+Plugin](http://wiki.rubyonrails.org/rails/pages/Uses+Guid+Plugin)

Thanks for the help
