51
37

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 5 years have passed since last update.

Laravel の migrate で Base table or view already exists というときに、migrate:refresh した

Posted at

php artisan migrate したらテーブルがあるよと言われました。

docker-compose exec phpfpm /var/www/laravel/artisan migrate

Illuminate\Database\QueryException  : SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'posts' already exists (SQL: create table `posts` (`id` int unsigned not null auto_increment primary key, `title` varchar(255) not null, `created_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

データベースのテーブルが既に存在する状態なので、エラーがでているみたいです。

migrate の一覧をだす

php artisan list をすると一覧がだせるようです。

docker-compose exec phpfpm /var/www/laravel/artisan list  | grep migrate
  migrate              Run the database migrations
 migrate
  migrate:fresh        Drop all tables and re-run all migrations
  migrate:install      Create the migration repository
  migrate:refresh      Reset and re-run all migrations
  migrate:reset        Rollback all database migrations
  migrate:rollback     Rollback the last database migration
  migrate:status       Show the status of each migration

migrate:fresh する

テーブルを捨てて作り直したいので、 php artisan migrate:fresh しました。

docker-compose exec phpfpm /var/www/laravel/artisan migrate:fresh

略

こんどはうまくいきました(☝ ՞ਊ ՞)

参考

51
37
1

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
51
37

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?