Hello all,
I''m once again struggling with a migration problem. I posted about this
last night, but I realize that this really is a separate problem and probably
needs its own thread.
I''m attempting to write a migration where I need foreign key
constraints. I used the code located at the following location to create a
migration_helpers.rb file:
http://seb.box.re/articles/2006/07/29/foreign-key-and-rails-migration#comments
Then, I added the migration_helpers.rb file under my lib directory in my site. I
changed the foreign key calls to look like:
foreign_key(:users_roles, :userid, :users)
However, I get the following complaint when I run rake:
rake aborted!
undefined method `foreign_key'' for
#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0xb75a5d0c>
The declaration in my migration file looks like this:
require "migration_helpers"
class MyWeb < ActiveRecord::Migration
extend MigrationHelpers
def self.up
I''ve also tried it as follows:
require "migration_helpers"
class MyWeb < ActiveRecord::Migration
include MigrationHelpers
def self.up
This is the first time I''ve tried to use a module, so I don''t
know what''s going on. I know that when I moved the helper file, I got a
complaint that rake couldn''t find it. This leads me to believe that the
helper was in the right location. Here are the contents of the helper file, by
the way.
module MigrationHelpers
def foreign_key(from_table, from_column, to_table)
execute %{alter table #{from_table}
add constraint #{self.to_contraint_name( from_table, from_column
)}
foreign key (#{from_column})
references #{to_table}(id)}
end
def drop_foreign_key(from_table, from_column, to_table)
execute "alter table #{from_table} DROP FOREIGN KEY
#{self.to_contraint_name(from_table, from_column)}"
end
def to_contraint_name(from_table, from_column)
return "fk_#{from_table}_#{from_column}"
end
end
Does anyone have any idea why this is failing?
---------------------------------
Get your email and more, right on the new Yahoo.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---