Laravel 5.4 Field Doesn't Have a Default Value

Laravel 5.4 field doesn't have a default value

Remove the guarded array and add the fillable instead:

protected $fillable = ['user_id', 'deal_id'];

SQLSTATE[HY000]: General error: 1364 Field 'branch_id' doesn't have a default value laravel 5.4

The branch_id is not visible to the model because it's not in fillable array.

In App\User.php

protected $fillable = [ ... ]; // add branch_id
// or
protected $guarded = [];

General error: 1364 Field 'status' doesn't have a default value

You need to put status to fillable array of your model, or add guarded = []; to your model.

User model

User
{
$fillable = [
// Add status here with other field
];

}

Why am I getting Field 'column' doesn't have a default value when using mass assignment (static::create) on a model class

After asking the question had to try and poke around just some more, and turns out that every field being set through the $model = static::query ()->create ($attributes); has to be in the fillable (or guarded) array, doesn't matter if its internally used or not.

My mistake for not realizing this sooner. For, of course, it IS just an array, being passed to the parent class static function that actually uses the $fillable array as if it was being used from the outside.

SQLSTATE[HY000]: General error: 1364 Field 'requisition_id' doesn't have a default value

In your submit_applications table, set nullable to requisition_id

public function up()
{
Schema::create('submit_applications', function (Blueprint $table) {
$table->increments('id');
$table->integer('requisition_id')->nullable()->unsigned();
$table->integer('school_id')->nullable()->unsigned();
$table->integer('approved')->nullable(true);
$table->string('application')->nullable(true);
$table->timestamps();
$table->foreign('requisition_id')->references('id')->on('requisitions');
$table->foreign('school_id')->references('id')->on('schools');
});
}


Related Topics



Leave a reply



Submit