Open
Description
When using schema-tool:update or migrations:diff on a MySQL < 5.7 the renaming of indices and the creation of foreign keys is in the wrong order which causes index updates to fail.
For example, this is what would be expected:
ALTER TABLE form_results DROP FOREIGN KEY form_results_forms_id;
ALTER TABLE form_results CHANGE form_id form_id INT DEFAULT NULL, CHANGE element_name element_name VARCHAR(255) NOT NULL;
DROP INDEX form_id ON form_results;
CREATE INDEX IDX_603CFEA45FF69B7D ON form_results (form_id);
ALTER TABLE form_results ADD CONSTRAINT FK_603CFEA45FF69B7D FOREIGN KEY (form_id) REFERENCES forms (id);
And this is what is actually generated:
ALTER TABLE form_results DROP FOREIGN KEY form_results_forms_id;
ALTER TABLE form_results CHANGE form_id form_id INT DEFAULT NULL, CHANGE element_name element_name VARCHAR(255) NOT NULL;
ALTER TABLE form_results ADD CONSTRAINT FK_603CFEA45FF69B7D FOREIGN KEY (form_id) REFERENCES forms (id);
DROP INDEX form_id ON form_results;
CREATE INDEX IDX_603CFEA45FF69B7D ON form_results (form_id);
As a temporary solution i've changed the order in which AbstractPlatform generates the SQL so the foreign keys get added last (Move rows 2081 - 2089 after 2106) but I don't think that solves this issue without breaking other platforms.