Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel sqlite迁移工作不正常_Laravel_Sqlite_Phpunit - Fatal编程技术网

Laravel 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

我正在使用Sqlite作为测试数据库。当我经营一家工厂时,它正在显示

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);