У меня есть 2 стола, badges
и counselors
. Все мои тесты были зелеными. Я добавил третью таблицу, сводную таблицу, названную badge_counselor
. Вот миграция:Тесты Lapare phpunit не будут правильно мигрировать
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');
}
}
Когда я бегу php artisan migrate
/php artisan migrate:refresh
/php artisan migrate:rollback
, все работает отлично. Как бы то ни было, когда я запускаю свои модульные тесты, ВСЕ из них терпят неудачу. И каждый из них возвращает сообщение об ошибке:
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))
или просто:
PDOException: SQLSTATE[HY000]: General error: 1 table "badge_counselor" already exists
Судя по сообщения об ошибке предположим, что таблица не упал правильно, но когда я запускать migrate
команды из терминал они идеальны. Я попытался сбросить таблицу migrations
, все таблицы и даже всю базу данных и создать ее снова, и ничего не работает.
Спасибо.
Просто помните, что я использую sqlite, а не MySQL. –