我运行Laravel,在OS X上使用MAMP,我试图做一些单元测试,使用PHPUnit和sqlite,但是当我运行我的测试时,出现错误Laravel测试,没有这样的表,sqlite
General error: 1 no such table: users
我试过运行工匠,手动迁移数据库,使用--env = testing,它运行良好,但我仍然得到错误。我甚至在SetUp方法中调用Artisan::call('migrate');
。
/app/config/testing/database.php
return [
'default' => 'sqlite',
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => ''
],
]
];
编辑: 迁移文件:
Schema::create('users', function($table) {
$table->increments('id');
$table->string('email', 32)->unique();
$table->string('password', 64);
$table->string('username', 32)->unique();
$table->dateTime('birthdate');
$table->enum('status', array('ACTIVE', 'INACTIVE'));
$table->timestamps();
});
Schema::create('roles', function($table) {
$table->increments('id');
$table->string('name', 32);
});
Schema::create('role_user', function ($table) {
$table->increments('id');
$table->unsignedInteger('user_id');
$table->unsignedInteger('role_id');
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('role_id')->references('id')->on('roles');
});
你能告诉我们你的迁移创建表用户吗?你在其他应用中使用哪个数据库? MySQL? –
是的,它是mysql,当我恢复工作时,我将添加迁移文件。 – Kao
在编辑中添加了迁移 – Kao