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粉1484347422023-10-23 14:55:23
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