Heim > Fragen und Antworten > Hauptteil
Ich habe kein Problem in Laravel 5.2, aber nach dem Erstellen der Migration für das Benutzermodell in Laravel 5.3 wird der folgende Fehler angezeigt:
SQLSTATE[HY000]:一般错误:1364 字段“family”没有默认值
! ! !
Unter Modellbenutzern:
protected $fillable = [ 'name', 'email', 'password', 'family', 'mobile', 'address', 'status' ];
Migration:
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(); });
Was ist mein Problem?
P粉1484347422023-10-23 14:55:23
您应该将 ->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');
比重新迁移:
php artisan migrate:rollback
和
php artisan migrate