Migration with foreign key won't work

Hi all

I use the plugin which supports foreign keys with migrations:

http://wiki.rubyonrails.org/rails/pages/Foreign+Key+Schema+Dumper+Plugin/versions/12

I have created the following migration file:

class AddArtistsTable < ActiveRecord::Migration
def self.up
create_table :artists, :force => true do |t|
t.column :name, :string, :limit => 100
t.column :artist_type_id, :integer
t.column :about, :text
end

create_table :artist_types, :force => true do |t|
  t.column :artist_type, :string, :limit => 20
  t.column :description, :string, :limit => 20
end

# Foreign Keys
add_foreign_key_constraint :artists, :artist_type_id, :artist_types, 

:artist_type, :on_update => :cascade, :on_delete => :restrict #
artists(artist_type_id) references artist_types(artist_type)
end

def self.down
drop_table :artists
drop_table :artist_types

# Foreign Keys
remove_foreign_key_constraint :artists, :foreign_key => 

:artist_type_id
end
end

When running it, everything goes well up to the foreign keys. I get the
following error:

– add_foreign_key_constraint(:artists, :artist_type_id, :artist_types,
:artist_type, {:on_delete=>:restrict, :on_update=>:cascade})
rake aborted!
Mysql::Error: Can’t create table
‘./psyguideorg_development/#sql-b0_14.frm’ (errno: 150): ALTER TABLE
artists ADD CONSTRAINT artists_ibfk_artist_type_id FOREIGN KEY
(artist_type_id) REFERENCES artist_types (artist_type) ON UPDATE CASCADE
ON DELETE RESTRICT

I can’t see where’s the problem… Can anybody help me, please?

Thanks a lot.
Joshua

These might help:

http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html
http://forums.devarticles.com/mysql-development-50/mysql-foreign-key-problem-errno-150t-7704.html
http://forums.mysql.com/read.php?22,19755,19755

-Jonathan.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs