Undefined method

I am very new to ROR. (Ruby 1.8.7, rails 2.1.1, rack 0.8.7, mysql 5.1.41)

I has my_app/lib/migration_helpers.rb file: module MigrationHelpers   def self.foreign_key(from_table, from_column, to_table)     constraint_name = "fk_#{from_table}_#{to_table}"

    execute %{alter table #{from_table}        add constraint #{constraint_name}           foreign key (#{from_column})           references #{to_table}(id)

    }.... end

In my_app/db/migrate/001_create_airports.rb:

require "migration_helpers" class CreateAirports < ActiveRecord::Migration   extend MigrationHelpers

  def self.up     create_table (:airports, :options => "ENGINE=InnoDB") do |t|       t.integer :country_id, :null => false #foreign key       t.string :code, :null => false, :limit => 3       t.string :name, :null => false, :limit => 45

      t.timestamps     end     foreign_key(:airports, :country_id, :countries)   end

  def self.down     drop_table :airports   end end

When I rake db:migration it got this error: -- create_table(:airports, {:options=>"ENGINE=InnoDB"})    -> 0.0156s -- foreign_key(:airports, :country_id, :countries) rake aborted! undefined method `foreign_key' for #<ActiveRecord::ConnectionAdapters::MysqlAdapter:0x5cf4d50>

What did I miss?

Thank you

I am very new to ROR. (Ruby 1.8.7, rails 2.1.1, rack 0.8.7, mysql 5.1.41)

I has my_app/lib/migration_helpers.rb file: module MigrationHelpers def self.foreign_key(from_table, from_column, to_table) constraint_name = "fk_#{from_table}_#{to_table}"

this should probably be just def foreign_key(...)

Fred

Frederick Cheung wrote in post #960395: