SQLSTATE[HY000]: General error: 1813 Tablespace '`laravel`.`migrations`' exists. の解決例

# エラー詳細

mysqlのコンテナを落としたら下記のエラーが発生しました


##### migrateコマンドの場合

```
 % docker-compose exec php php artisan migrate         

   Illuminate\Database\QueryException 

  SQLSTATE[HY000]: General error: 1813 Tablespace '`laravel`.`migrations`' exists. (SQL: create table `migrations` (`id` int unsigned not null auto_increment primary key, `migration` varchar(255) not null, `batch` int not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
    667|         // If an exception occurs when attempting to run a query, we'll format the error
    668|         // message to include the bindings with SQL, which will make this exception a
    669|         // lot more helpful to the developer instead of just the database's errors.
    670|         catch (Exception $e) {
  > 671|             throw new QueryException(
    672|                 $query, $this->prepareBindings($bindings), $e
    673|             );
    674|         }
    675| 

      +39 vendor frames 
  40  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
```

##### freshコマンドの場合

```

% docker-compose exec php php artisan migrate:fresh   
Dropped all tables successfully.

   Illuminate\Database\QueryException 

  SQLSTATE[HY000]: General error: 1813 Tablespace '`laravel`.`migrations`' exists. (SQL: create table `migrations` (`id` int unsigned not null auto_increment primary key, `migration` varchar(255) not null, `batch` int not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
    667|         // If an exception occurs when attempting to run a query, we'll format the error
    668|         // message to include the bindings with SQL, which will make this exception a
    669|         // lot more helpful to the developer instead of just the database's errors.
    670|         catch (Exception $e) {
  > 671|             throw new QueryException(
    672|                 $query, $this->prepareBindings($bindings), $e
    673|             );
    674|         }
    675| 

      +51 vendor frames 
  52  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
kontech@MacBook-Pro construction_management_system % 
```


# 解決した方法
##### ・コンテナ（docker）にログイン

```
#　mysqlのコンテナ名を確認
 % docker ps
CONTAINER ID        IMAGE                                COMMAND                  CREATED             STATUS              PORTS                                     NAMES
b683d1147a97        nginx:stable-alpine                  "nginx -g 'daemon of…"   38 minutes ago      Up 37 minutes       0.0.0.0:8080->80/tcp                      nginx
7345eb3d7172        construction_management_system_php   "docker-php-entrypoi…"   38 minutes ago      Up 38 minutes       80/tcp, 443/tcp, 0.0.0.0:9000->9000/tcp   php
82289ada823c        mysql:5.7                            "docker-entrypoint.s…"   38 minutes ago      Up 38 minutes       33060/tcp, 0.0.0.0:4306->3306/tcp         mysql

# ログインコマンド
 % docker exec -it 82289ada823c /bin/bash
# 下記のコマンドでログインを確認できた
root@82289ada823c:/# 
```

ログインの参考
https://qiita.com/TakahiroSakoda/items/5180ff9762ebddb0bd4d

##### ・dockerの中の/var/lib/mysqlの中に削除したはずのlaravel(データベースの残骸)を削除

```
# 現況のファイルを探す
root@82289ada823c:/# cd /var/lib/mysql
root@82289ada823c:/# ls
auto.cnf    ca.pem	     client-key.pem  ib_logfile0  ibdata1  laravel  performance_schema	public_key.pem	 server-key.pem
ca-key.pem  client-cert.pem  ib_buffer_pool  ib_logfile1  ibtmp1   mysql    private_key.pem	server-cert.pem  sys

# laravel(データベースで中にテーブルが入ってます)を削除
root@82289ada823c:/# rm -rf laravel

# laravel(データベース（テーブルの入れ物）)は必要だったみたいだったので下記コマンドでフォルダだけ作成し直しました
root@82289ada823c:/# mkdir laravel

※参考としてlaravelの中身を添付しておきます
root@82289ada823c:/var/lib/mysql/laravel# ls
failed_jobs.ibd  migrations.ibd  operation_amounts.ibd	operations.ibd	password_resets.ibd  projects.ibd  reasons.ibd	record_timings.ibd  users.ibd

# 上記ののち、下記コマンドで正常な挙動をしました。
% docker-compose exec php php artisan migrate       
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table (0.1 seconds)
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table (0.06 seconds)
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated:  2019_08_19_000000_create_failed_jobs_table (0.03 seconds)
Migrating: 2020_05_02_081128_create_projects_table
Migrated:  2020_05_02_081128_create_projects_table (0.13 seconds)
Migrating: 2020_05_02_091702_create_record_timings_table
Migrated:  2020_05_02_091702_create_record_timings_table (0.15 seconds)
Migrating: 2020_05_02_094345_create_operations_table
Migrated:  2020_05_02_094345_create_operations_table (0.12 seconds)
Migrating: 2020_05_02_094954_create_operation_amounts_table
Migrated:  2020_05_02_094954_create_operation_amounts_table (0.14 seconds)
Migrating: 2020_05_02_100233_create_reasons_table
Migrated:  2020_05_02_100233_create_reasons_table (0.11 seconds)
```
SQLSTATE[HY000]: General error: 1813 Tablespace '`laravel`.`migrations`' exists.の解決の参考にしたページ
https://stackoverflow.com/questions/15694168/error-tablespace-for-table-xxx-exists-please-discard-the-tablespace-before-imp