添加全文索引后在Laravel中运行PHPUnit时出错
Doctrine\DBAL\Driver\PDOException: SQLSTATE[HY000]: General error: 1 near "name": syntax error在调查之后,我添加的迁移所导致的错误
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddFulltextIndexToProductName extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::statement('ALTER TABLE products ADD FULLTEXT fulltext_index(name)');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
DB::statement('DROP INDEX `fulltext_index`');
}
}如果删除该迁移代码,则测试将优雅地运行。
有人经历过这个问题吗?
发布于 2020-05-30 09:15:37
通常,Laravel测试在内存sqlite数据库中使用,迁移过程中的此语句将无法工作。您可以在这里检查如何创建sqlite全文索引:https://www.sqlitetutorial.net/sqlite-full-text-search/
因为Laravel不支持全文搜索,所以我假设您已经编写了自定义函数,它可能也不会在测试中工作。
为了克服这个问题,你可以:
if(env('APP_ENV') === 'testing')https://stackoverflow.com/questions/62099518
复制相似问题