在laravel中运行迁移时出现此错误。我重新检查了模式中的数据类型是否为字符串。
正如您在模式中看到的那样,数据类型是一个字符串,但仍然得到这个错误。有什么解决方案吗?
MongoDB\Exception\InvalidArgumentException
Expected "name" option to have type "string" but found "int"
at D:\CRUD\CRUD\vendor\mongodb\mongodb\src\Exception\InvalidArgumentException.php:60
56▕
57▕ $expectedType = $typeString;
58▕ }
59▕
➜ 60▕ return new static(sprintf('Expected %s to have type "%s" but found "%s"', $name, $expectedType, get_debug_type($value)));
61▕ }
62▕ }
63▕
1 D:\CRUD\CRUD\vendor\mongodb\mongodb\src\Model\IndexInput.php:71
MongoDB\Exception\InvalidArgumentException::invalidType(""name" option", "string")
2 D:\CRUD\CRUD\vendor\mongodb\mongodb\src\Operation\CreateIndexes.php:118
MongoDB\Model\IndexInput::__construct([])迁移停止的地方
public function up()
{
Schema::create('personal_access_tokens', function (Blueprint $table) {
$table->morphs('tokenable');
$table->index('name');
$table->unique('token', 64);
$table->text('abilities')->nullable();
$table->timestamp('last_used_at')->nullable();
$table->timestamps();
});
}发布于 2021-08-31 09:31:06
您的问题是更改了Laravel Sanctum migration的实际实现。
$table->unique()期望第一个参数是列的name,第二个参数(可选)是唯一索引的name,但最初的实现使用$table->string('name', 64)->unique();,因此第一个参数是列name,而第二个参数是列的size,所以它与名称不同……
https://stackoverflow.com/questions/68994349
复制相似问题