Forum: Ruby on Rails name of foreign key in innodb table

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
psimoes (Guest)
on 2007-06-26 15:07
(Received via mailing list)
Hello,

I'm trying to do a ALTER TABLE to add a foreign key. The code is:

execute "ALTER TABLE table1
                                ADD CONSTRAINT FOREIGN KEY
`const_fk_table1_table2_id` (`table2_id`)
                                REFERENCES `table2` (`id`)
                                ON DELETE CASCADE"

Instead of creating a foreign key constraint with the name
"const_fk_table1_table2_id" it will create one with the name
"table2_ibfk_1".

First I've added an index with :  add_index :table1, :table2_id, :name
=> 'fk_table1_table2_id'

Am I doing something wrong?
psimoes (Guest)
on 2007-06-26 15:14
(Received via mailing list)
Problem fixed. The name comes after the CONSTRAINT not the FOREIGN KEY
keywords.
This topic is locked and can not be replied to.