I have 2 tables, badges
and counselors
. All of my tests were green. I added a third table, a pivot table, named badge_counselor
. Here is the migration:
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateBadgeCounselorTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('badge_counselor', function (Blueprint $table) {
$table->increments('id');
$table->integer('badge_id')->unsigned();
$table->integer('counselor_id')->unsigned();
$table->foreign('badge_id')->references('id')->on('badges')->onDelete('cascade');
$table->foreign('counselor_id')->references('id')->on('counselors')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('badge_counselor');
}
}
When i run php artisan migrate
/ php artisan migrate:refresh
/ php artisan migrate:rollback
, everything works fine. Howevever, when i run my unit tests, ALL of them fail. And each one returns the error message:
Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 table "badge_counselor" already exists (SQL: create table "badge_counselor" ("id" integer not null primary key autoincrement, "badge_id" integer not null, "counselor_id" integer not null, foreign key("badge_id") references "badges"("id") on delete cascade, foreign key("counselor_id") references "counselors"("id") on delete cascade))
or simply:
PDOException: SQLSTATE[HY000]: General error: 1 table "badge_counselor" already exists
Judging by the error message a assume that the table is not being dropped correctly, but when i run the migrate
commands from the terminal they are perfect. I have tried dropping the migrations
table, all the tables, and even the entire database and creating it again and nothing seems to work.
Thanks.