Расширяя ответ @ Dewey, вот небольшой скрипт для переименования FK, сгенерированных Hibernate, полезным способом ("FK__" + table name + "__" + referenced table name)
.
SELECT CONCAT(
"alter table ", TABLE_NAME, " drop foreign key ", CONSTRAINT_NAME,";\n",
"alter table ", TABLE_NAME, " drop key ", CONSTRAINT_NAME, ";\n",
"alter table ", TABLE_NAME, " add key FK__", table_name, "__",
referenced_table_name, " (", column_name, ");\n",
"alter table ", TABLE_NAME, " add constraint FK__", table_name, "__",
referenced_table_name , " foreign key (", column_name, ") ",
"references ", referenced_table_name,
"(", referenced_column_name, ");"
) AS runMe
FROM
information_schema.key_column_usage
WHERE
TABLE_SCHEMA='myschemaname'
AND
constraint_name like 'FK_%';
Бит вывода:
alter table visitor_browsers drop foreign key FK_4ygermmic4fujggq1kp96dx47;
alter table visitor_browsers drop key FK_4ygermmic4fujggq1kp96dx47;
alter table visitor_browsers add key FK__visitor_browsers__websites (website);
alter table visitor_browsers add constraint FK__visitor_browsers__websites foreign key (website) references websites(id);