我在 Laravel 5.2 中没有问题,但在 Laravel 5.3 中为用户模型创建迁移后,它显示以下错误:
SQLSTATE[HY000]:一般错误:1364 字段“family”没有默认值!!!
在模型用户中:
protected $fillable = [
'name', 'email', 'password', 'family', 'mobile', 'address', 'status'
];
迁移中:
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('family');
$table->string('mobile')->unique();
$table->string('address');
$table->boolean('status');
$table->string('email')->unique();
$table->string('password');
$table->integer('reagent');
$table->rememberToken();
$table->timestamps();
});
我的问题出在哪里?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
您应该将
->nullable()或->default('somethingHere')添加到发送空值的字段。$table->string('family')->nullable(); //this means that if you send empty value this field will become MySQL NULL或者设置默认值:
$table->string('family')->default('default value here');比重新迁移:
和