[RUBY] [Deployment error] Mysql2 :: Error: Table'~' already exists: CREATE TABLE `~`

What is this

Error during automatic deployment on Capistrano during team development on Rails What to do when "Mysql2 :: Error: Table'~' already exists: CREATE TABLE~" appears. Translated literally, it's impossible because there is already a table.


The bottom line is database scrap and build. You were to become Shiva, the god of imagination and destruction.

I will do it seriously. .. .. First, SSH in from the terminal and connect to AWS. After logging in, connect to mysql and take a look at the contents.

[ec2-user@]$ mysql -u root -p

#mysql password
Enter password:

Once in mysql, take a look at the production database.

mysql> show databases;
| Database                         |
| information_schema               |
| sample_production                |
| mysql                            |
| performance_schema               |

mysql> show tables from sample_production;
| Tables_in_sample_production                |
| ar_internal_metadata                       |
| schema_migrations                          |
| user_addresses                             |
| users                                      |

Delete this with the drop command.

mysql> drop database sample_production;

mysql> exit

Move the directory and create the database.

$ cd  /var/www/app name/current

[ec2-user@ current]$ rails db:create RAILS_ENV=production;

#If necessary, here too
[ec2-user@ current]$ rails db:migrate RAILS_ENV=production;

later, bundle exec cap production deploy And it's done.

Thank you very much! !!

Recommended Posts

[Deployment error] Mysql2 :: Error: Table'~' already exists: CREATE TABLE `~`
Mysql2 :: Error: Table'relationships' already exists
(Solution) Mysql2 :: Error: Table'users' already exists
[rails] heroku deployment error ActionView :: Template :: Error (Mysql2 :: Error: Table --- doesn't exist):
Deployment error
MySql connection error
Resolve Mysql2 :: Error :: ConnectionError