Foreign key plugin

Hi guys, i have just installed the foreign key pluging from http:// www.redhillconsulting.com.au/ rails_plugins.html#foreign_key_migrations.

The problem that I'm facing is the following: I have set up migrations for 7 tables in a MySQL database. However, when I try to execute rake db:migrate i get the following error:

== CreateInterests: migrating

Are you sure there exists in the DB a locations table with an id field and an interest_types table with an id column?

The locations and interest_types migration files don't explicitly define the id field. If I'm not mistaken, you don't have to specifcy the id field. Or will the problem be solved if the interest_types en locations table ALREADY exist, before I apply any foreign keys?

Yes. Its create_table must come before, because the constraint needs to refer to some column known by the database.

When you use that plugin the order of (create|drop)_table matters.

-- fxn

The migration for interest_types looks like this:

class CreateInterests < ActiveRecord::Migration   def self.up     create_table :interests do |t|       t.column :location_id, :integer, :null => false       t.column :interest_type_id, :integer, :null => false     end   end

  def self.down     drop_table :interests   end end

I have deleted the other 6 migrations. If I perform rake db:migrate I still get this error:

== CreateInterests: migrating

*Before* that migration runs, tables "locations" and "interest_types" must have been created, possibly in earlier migrations.

-- fxn