{"action":"closed","issue":{"url":"https://api.github.com/repos/rails/rails/issues/19396","labels_url":"https://api.github.com/repos/rails/rails/issues/19396/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/19396/comments","events_url":"https://api.github.com/repos/rails/rails/issues/19396/events","html_url":"https://github.com/rails/rails/issues/19396","id":62838626,"number":19396,"title":"Migrations for reference removal generate statements in problematic order","user":{"login":"vemv","id":1162994,"avatar_url":"https://avatars.githubusercontent.com/u/1162994?v=3","gravatar_id":"","url":"https://api.github.com/users/vemv","html_url":"https://github.com/vemv","followers_url":"https://api.github.com/users/vemv/followers","following_url":"https://api.github.com/users/vemv/following{/other_user}","gists_url":"https://api.github.com/users/vemv/gists{/gist_id}","starred_url":"https://api.github.com/users/vemv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vemv/subscriptions","organizations_url":"https://api.github.com/users/vemv/orgs","repos_url":"https://api.github.com/users/vemv/repos","events_url":"https://api.github.com/users/vemv/events{/privacy}","received_events_url":"https://api.github.com/users/vemv/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-19T01:05:28Z","updated_at":"2015-03-19T09:15:41Z","closed_at":"2015-03-19T09:15:41Z","body":"The following:\r\n\r\n`rails g migration remove_contest_from_prizes contest:references`\r\n\r\nGenerates these 2 statements:\r\n\r\n```ruby\r\n    remove_reference :prizes, :contest, index: true\r\n    remove_foreign_key :prizes, :contests\r\n```\r\n\r\nHowever the migration won't run successfully on MySQL:\r\n\r\n```\r\nMysql2::Error: Cannot drop index 'index_prizes_on_contest_id': needed in a foreign key constraint: ALTER TABLE `prizes` DROP `contest_id`/Users/vemv/khana/db/migrate/20150319005657_remove_contest_from_prizes.rb:3:in `change'\r\nActiveRecord::StatementInvalid: Mysql2::Error: Cannot drop index 'index_prizes_on_contest_id': needed in a foreign key constraint: ALTER TABLE `prizes` DROP `contest_id`\r\n```\r\n\r\nThis can be fixed by editing the migration so the `remove_foreign_key` statement runs before the `remove_reference` statement.\r\n\r\nWould it be good to ensure that particular order?"}}