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
How to Create a Custom Admin Page in Opencart
How to Switch from Post to Get in PHP Curl
PHP - Get Numeric Index of Associative Array
How to Get File Url Using Storage Facade in Laravel 5
PHP Errors Not Being Displayed in the Browser [Ubuntu 10.10]
How to Count the Numbers of Rows That a MySQL Query Returned
Function to Return Only Alpha-Numeric Characters from String
How to Write a Stored Procedure in PHPmyadmin
What Does Using a Single Pipe '|' in a Function Argument Do
PHP Flush That Works... Even in Nginx
How to Force Laravel Project to Use Https for All Routes
When Should I Use Stdclass and When Should I Use an Array in PHP Oo Code
How to Prevent Multiple Logins in PHP Website
Display Data from SQL Database into PHP/ HTML Table
How to Declare a Two Dimensional Array
What Do the Ent_Html5, Ent_Html401, ... Modifiers on HTML_Entity_Decode Do