错误字段在laravel 5.3中没有默认值 [英] Error Field doesn't have a default value in laravel 5.3
本文介绍了错误字段在laravel 5.3中没有默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在为用户模型创建迁移之后,在Laravel 5.2中没有问题,但是在Laravel 5.3中,它显示了以下错误:
I have no problem in Laravel 5.2 but in Laravel 5.3 after create migration for user model, It shows me following error:
SQLSTATE[HY000]: General error: 1364 Field 'family' doesn't have a default value
!!!
在模型用户中:
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();
});
我的问题在哪里?
推荐答案
您应该在发送空值的字段中添加->nullable()
或->default('somethingHere')
.
You should add ->nullable()
or ->default('somethingHere')
to fields which you send empty values.
$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');
比移民:
php artisan migrate:rollback
和
php artisan migrate
这篇关于错误字段在laravel 5.3中没有默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文