Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
10
Help us understand the problem. What are the problem?

posted at

updated at

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

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で中身を確認してところ、無事消えていた。

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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
10
Help us understand the problem. What are the problem?