2016-11-29 74 views
0

我有2个表,badgescounselors。我所有的测试都是绿色的。我添加了第三个表,一个数据透视表,名为badge_counselor。下面是迁移:Laravel 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,一切工作正常。 Howevever,当我运行我的单元测试时,所有的都失败了。而且每一个返回错误消息:

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表,所有的表,甚至整个数据库,并再次创建它,似乎没有任何工作。

谢谢。

回答

0

你在使用MySQL吗?如果是这样,可能尝试删除整个数据库并重新创建它,但确保您的数据库位于InnoDB中,而不是MyISAM。为此,请在phpMyAdmin的变量部分将default_storage_engine更改为InnoDB

+0

只记得我使用sqlite,而不是MySQL。 –

0

[解决方案]不完全确定发生了什么,但我删除了我用于phpunit的sqlite文件,然后再次运行它们。