美好的一天 我有一个Laravel 7项目遇到了一些问题,首先我遇到了这个错误
我为该错误找到的解决方案是在config/database.php
中将"严格"值编辑为 false。这修复了错误。但是现在我才意识到,每次我创建一个用户时,id的值总是"0"示例
这是我的迁移
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('phone_number');
$table->string('client_address');
$table->rememberToken();
$table->timestamps();
});
}
这是因为您在表中id
字段不是AuthoIncrement
首先删除数据库中users
表,然后删除数据库中migrations
表中create_users_table
记录,然后将迁移更改为此
$table->bigIncrements('id');
然后php artisan migrate