错误字段在 laravel 5.3 中没有默认值 [英] Error Field doesn't have a default value in laravel 5.3

查看:20
本文介绍了错误字段在 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]:一般错误: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();
    });

我的问题在哪里?

推荐答案

你应该添加 ->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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆