suchen

Heim  >  Fragen und Antworten  >  Hauptteil

Fehler in Laravel 5.3: Feld hat keinen Standardwert

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粉903052556P粉903052556388 Tage vor557

Antworte allen(1)Ich werde antworten

  • P粉148434742

    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

    Antwort
    0
  • StornierenAntwort