0

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.

Luke Sweeney
  • 905
  • 1
  • 7
  • 17

2 Answers2

0

Are you using MySQL? If so, probably try deleting the entire database and create it again but make sure that your database is in InnoDB and not MyISAM. For this, change the default_storage_engine to InnoDB in the Variables section in phpMyAdmin.

ettdro
  • 340
  • 4
  • 15
0

[Solution] Not exactly sure what was going on but i deleted the sqlite file that i was using for phpunit, then ran them again.

Luke Sweeney
  • 905
  • 1
  • 7
  • 17