Error in Laravel 5.3: Field has no default value
P粉903052556
P粉903052556 2023-10-22 19:57:57
0
1
588

I have no problem in Laravel 5.2, but after creating a migration for the User model in Laravel 5.3, it shows the following error:

SQLSTATE[HY000]: General error: 1364 Field "family" has no default value! ! !

In model users:

protected $fillable = [
    'name', 'email', 'password', 'family', 'mobile', 'address', 'status'
];

Migrating:

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();
    });

What is my problem?

P粉903052556
P粉903052556

reply all(1)
P粉148434742

You should add ->nullable() or ->default('somethingHere') to fields that send null values.

$table->string('family')->nullable(); //this means that if you send empty value this field will become MySQL NULL

Or set the default value:

$table->string('family')->default('default value here');

Than re-migration:

php artisan migrate:rollback

and

php artisan migrate
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template