0
votes

When I run php artisan migrate:refresh in the terminal, I get the following error. Why am I getting this error?

[Illuminate\Database\QueryException] SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'departments' already exists (SQL: create table departments (id int unsigned not null auto_increment primary key, name varchar(191) not null, deleted_at timestamp null, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate utf8mb4_unicode_ci engine = InnoDB)

[PDOException] SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'departments' already exists

2
Okay2 @KenWhitegwapo
I updated already @KenWhitegwapo
I edited already @KenWhitegwapo
did you write down function for departments yet?Felix
With regard to your question, you usually get that error when your migrations are out of sync. The database has been rolled back, and when recreating the table departments, it's found to already exist. If you're dropping all tables anyway, it would be easiest to manually drop all tables, and to re-run your migrations. Then run php artisan migrate:refresh again to see if anything in your migrations is actually still broken.fubar

2 Answers

1
votes

Try to run php artisan migrate:fresh it should help. But the problem is some down method in the migrate does not cancel up method changes or you have changed some migrations after ran php artisan migrate

0
votes

Please, check if you have the down() method configured in your departments migration.

public function down()
{
    Schema::dropIfExists('departments');
}