LoginSignup
0
0

More than 3 years have passed since last update.

Mysql2::Error: Table ' ~~~~~ ' already existsと表示され他時の対処法

Posted at

・マイグレーションしようとしたときにこのようなエラーが出た。
 
-- create_table(:microposts)
rails aborted!
StandardError: An error has occurred, all later migrations canceled:

Mysql2::Error: Table 'microposts' already exists
~省略~
Caused by:
ActiveRecord::StatementInvalid: Mysql2::Error: Table 'microposts' already exists
~省略~
Caused by:
Mysql2::Error: Table 'microposts' already exists
~省略~


・エラーの意味は「もうすでに同じテーブルがありますよ。」といった感じのエラー。
・この状況になったらテーブルを消すことで解決する。

手順
・rails dbでデータベースを開く。
・mysqlが開くので、SHOW TABLES;を打ち込む。
・上記の例のエラーに関するとmicropostsを消す事になるが、各々違うと思うので、臨機応変に対応。
drop table 〜〜〜;で消す。
・削除ができたかどうかをSHOW TABLES;で確認。
・exitで抜ける。
・rails db:migrateを実行。

完   

0
0
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
0
0