12
16

More than 1 year has passed since last update.

MySQLでインデックスや外部キー制約をリネームする

Last updated at Posted at 2015-04-05

TL;DR

5.6系だとRENAME INDEXができないので以下のSQLを実行する。

ALTER TABLE posts
  ADD KEY index_posts_on_category_id(category_id),
  ADD UNIQUE KEY index_posts_on_url(url),
  DROP KEY new_index_posts_on_category_id,
  DROP KEY new_index_posts_on_url,
  ADD CONSTRAINT
    posts_blog_id_fk
      FOREIGN KEY(blog_id)
      REFERENCES blogs,
  DROP FOREIGN KEY new_posts_blog_id_fk;

詳しくは以下のブログ記事をご覧ください。

12
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
16