Laravel 5.4 field doesn't have a default value

后端 未结 7 786
执念已碎
执念已碎 2020-12-14 06:37

I am having this error and none of the googled result i checked is similar to my problem.

I have an application with class Deal, User, and Matches

A deal has

相关标签:
7条回答
  • 2020-12-14 07:26

    If you have a constructor in your model, just make sure it has a call to a parent constructor as well:

    public function __construct( array $attributes = array() ) {
        // mandatory
        parent::__construct($attributes);
    
        //..
    }
    

    Otherwise, it will break some functionality like Model::create.

    0 讨论(0)
  • 2020-12-14 07:28

    If you would like to revert to previous behavior, update your

    config/database.php

    file and set 'strict' => false for your connection.

    0 讨论(0)
  • 2020-12-14 07:29

    Since it was a unique field in my case, I could not make it nullable.

    For me, I had an empty constructor which was causing the issue don't know why. Please comment if anyone knows the reason.

    public function __construct(){
    
    }
    

    Commenting/removing it resolved the issue.

    0 讨论(0)
  • 2020-12-14 07:29

    I am using Laravel 8 and fixed this error thorugh this two steps:

    1. move the word from $guarded array to $fillable array in User Mode

    2. Config.database.php: 'strict' => false in the array of 'mysql'

    0 讨论(0)
  • 2020-12-14 07:33

    Another way around this error is to include

    'strict' => false,

    into config/database.php within mysql array

    0 讨论(0)
  • 2020-12-14 07:36

    Remove the guarded array and add the fillable instead:

    protected $fillable = ['user_id', 'deal_id'];
    
    0 讨论(0)
提交回复
热议问题