Issue
Getting this error while running migration in laravel. I Have rechecked my data type in the schema is a string.
As you can see in the schema the datatype is a string but still getting this error. Any solutions???
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([])
Migration where it stopped
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();
});
}
Solution
Your problem is that you have changed the actual implementation of Laravel Sanctum migration
.
$table->unique()
expects first parameter to be the column’s name
and second (optional) to be the unique index’s name
, but the original implementation uses $table->string('name', 64)->unique();
, so the first one is the column name
, but the second one is the column’s size
, so that is not the same as a name…
Answered By – matiaslauriti
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0