Migrations + foreign keys

Hi all,

In the AWDR author use the execute method to declare foreign keys:

execute “alter table… add constraint… foreign key…”

Is there a ruby sintax to declare a foreign key in a migration class?

On 7/13/06, Eduardo Yáñez Parareda [email protected] wrote:

Hi all,

In the AWDR author use the execute method to declare foreign keys:

execute “alter table… add constraint… foreign key…”

Is there a ruby sintax to declare a foreign key in a migration class?

I’ve not used it, but there is a foreign key migrations plugin.

http://www.redhillconsulting.com.au/rails_plugins.html#foreign_key_migrations

http://www.redhillconsulting.com.au/rails_plugins.html#foreign_key_migrations

Thanks, I’m going to have a quick look at this

I didn’t realize the solution proposed in the book. Create a new module
with
a foreign_key method which invokes execute alter table, and include that
module
in the migration’s classes that need it.

On 7/14/06, Pat M. [email protected] wrote:

Which book?

2nd edition of Agile Web D. With Rails. Page 268.

– James

Which book?

I had problems with the foreign_key_migrations plugin. Is was possible
to
generate a contraint that was not removable via MySQL ddl. Only
solution
was to drop and re-create the database. Happened twice. ( In all
fairness, I
haven’t researched the problem, and haven’t contacted the autors about
it).

I am using the foreign_key_schema_dumper plugin in my current project.
It
provides to migration methods for managing foreign keys in migrations.

add_foreign_key_constraint
and
remove_foreign_key_constraint

You might want to look to see how they are implements, or just use them
if
they do what you want.
my 2 cents
-Larry