jeudi 31 octobre 2019

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

here's the error

SQLSTATE[HY000]: General error: 1364 Field 'department_id' doesn't have a default value (SQL: insert into `ms_user` (`name`, `username`, `role`, `email`, `password`, `updated_at`, `created_at`)

ms_user model

protected $fillable = [
        'department_id','name', 'email', 'password','username','role',
    ];

create function :

    {
        return ms_user::create([
            'name' => $data['name'],
            'username' => $data['username'],
            'role' => $data['role'],
            'email' => $data['email'],
            'department_id' => $data['department_id'],
            'password' => bcrypt($data['password'])
        ]);
    }

validator function :

 protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|string|max:255',
            'username' => 'required|string|max:255',
            'role' => 'required|in:user,admin',
            'department_id' => 'required|string',
            'email' => 'required|string|email|max:255|unique:ms_user',
            'password' => 'required|string|min:6|confirmed',
        ]);
    }

department_id is a dropdown menu that contains data from the ms_department table, department_id becomes the foreign key in the ms_user table and as the primary key in the ms_department



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/36pH7xI
via IFTTT

Aucun commentaire:

Enregistrer un commentaire