我在OS X上使用MAMP运行Laravel,并且尝试使用PHPUnit和sqlite进行一些单元测试,但是当我运行测试时,出现错误
一般错误:1没有这样的表:users
我尝试使用--env = testing运行工匠,以手动迁移数据库,该程序运行良好,但是仍然出现错误。我什至调用Artisan::call('migrate');
SetUp方法。
/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');
});
SQLite不支持该ENUM
类型:http : //www.sqlite.org/datatype3.html
这就是为什么没有创建用户表的原因。您将必须在经典的MySQL表上运行测试或删除所有ENUM
类型。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句