Thursday, September 10, 2009

ERROR 1005 (HY000): Rails Migrations for Unsigned Integers

ERROR 1005 (HY000): Can't create table './*/#sql-3e29_1209.frm' (errno: 150)

If you are getting this when trying to add a foreign key constraint make sure the columns are of the same type. This includes attributes! Specifically pay attention to signed vs. unsigned columns. Just because two columns are integer (or int(10) or int(11)), you won't be able to create a foreign key constraint between them unless they are have the same sign.

Furthermore, in a Rails Migration, to get a signed/unsigned column use the following:

create_table :tblFoo, :primary_key => :UID do |t|
t.column 'Bar', 'int(10) unsigned', :null => false

No comments: