15
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【解決方法】Mysql2::Error: Table 'users' already exists

Last updated at Posted at 2020-04-05

#Mysql2::Error: Table 'users' already existsエラーに遭遇

Mysql2::Error: Table 'users' already exists
どうやらusersテーブルが既に存在しているため、マイグレートが実行できない様子 解決方法として既に存在するusersテーブルを削除し、再びマイグレートすれば良さそうだ

ターミナルで以下のコマンドを実行

$ rails db:

すると

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 490
Server version: 5.6.47 Homebrew

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

長々と文章が出てくるが、とりあえず次のコマンドを実行
mysql> SHOW TABLES;
mysqlのテーブルが表示される
+---------------------------+
| Tables_in_app_development |
+---------------------------+
| ar_internal_metadata      |
| posts                     |
| schema_migrations         |
| users                     |
+---------------------------+

ここからusersテーブルを消すために、次のコマンドを実行

mysql> drop table テーブル名;

今回はusersテーブルなので

mysql> drop table users;
Query OK, 0 rows affected (0.04 sec)

削除完了。 sequelProで中身を確認してところ、無事消えていた。

ターミナル上の操作はなかなか覚えられないが、こうした作業ができるのを知っておくのが大切かなと。

15
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
15
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?