Laravel sqlite迁移工作不正常
我正在使用Sqlite作为测试数据库。当我经营一家工厂时,它正在显示Laravel sqlite迁移工作不正常,laravel,sqlite,phpunit,Laravel,Sqlite,Phpunit,我正在使用Sqlite作为测试数据库。当我经营一家工厂时,它正在显示 SQLSTATE[HY000]:一般错误:1靠近“自动增量”:语法错误 从SQLite文档中,它们有自动增量而不是自动增量 如何为sqlite定义主键或自动增量 我正在使用刷新数据库 迁移: Schema::create('teachers',函数(Blueprint$table){ $table->increments('id'); $table->string('name',100); 工厂: $factory->def
SQLSTATE[HY000]:一般错误:1靠近“自动增量”:语法错误
从SQLite文档中,它们有自动增量
而不是自动增量
如何为sqlite定义主键或自动增量
我正在使用刷新数据库
迁移:
Schema::create('teachers',函数(Blueprint$table){
$table->increments('id');
$table->string('name',100);
工厂:
$factory->define(教师::类,函数)(Faker$Faker){
返回[
'name'=>$faker->name
];
});
phpunit.xml
config/database.php
“连接”=>[
“sqlite”=>[
“驱动程序”=>“sqlite”,
'url'=>env('DATABASE_url'),
'database'=>数据库路径('database.sqlite'),
'前缀'=>'',
“外键约束”=>env(“DB\U外键”,true),
],
....
测试用例
公共功能用户可以访问教师页面()
{
$teacher=factory('App\Models\teacher')->create();
$response=$this->get(路由('teachers.index',$teacher->id));
$response->assertStatus(200);
}
完整错误消息为:
illumb\Database\QueryException:SQLSTATE[HY000]:一般错误:1靠近“auto_increment”:语法错误(SQL:create table`teachers`(`id`int unsigned not null auto_increment主键,`name`varchar(100)not null))
- 拉威尔5.8
- PHPUnit 7.5.17
- PHP7.2
- 我在我的
文件上启用了php.ini
pdo_sqlite
您使用的是什么版本的Laravel?我使用的是Laravel 5.8,因此它迁移了“用户”和“密码重置”表,但在“教师”上失败了?是的,这很奇怪。
dd(Schema::connection($this->getConnection())->getConnection()->getSchemaGrammar())
告诉我:App\Services\ExtendedMysqlGrammar
是您添加到应用程序中的东西。在测试时,您不必使用它。问题在于雄辩的语法生成auto_increment
对于sqlite是不正确的。
Schema::create('teachers', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name', 100);