Fehler in Laravel 5.3: Feld hat keinen Standardwert
P粉903052556
P粉903052556 2023-10-22 19:57:57
0
1
570

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粉903052556
P粉903052556

Antworte allen(1)
P粉148434742

您应该将 ->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
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage