Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Emokores's avatar

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

I have a form submitting a bunch of data. I seem to have all the values printed when I dd($request). But when I make an actual submission to the database, I get an Illuminate\Database\QueryException that tellsme one of the fields has no default value.

I am using Actions and Custom form Requests:

// This is in my rules() function

return [
	'name' => ['required', 'string'],
	'email' => ['email', 'nullable', 'unique:patients,email'],
	'gender' => ['required'],
	'age_type' => ['required'],
	'age' => ['required', 'numeric'],
	'dob' => ['required'],
	'address' => ['required'],
	'occupation' => ['required'],
	'mobile_number' => ['required'],
	'nok_id' => ['required'],
	'relation_to_next_of_kin' => ['required'],
	'other_relation_to_next_of_kin' => ['required_if:relation_to_next_of_kin,5'],
	'referral_point' => ['required'],
	'referral_point_details' => ['required_if:referral_point,2,4,5'],
	'other_referral_point_details' => ['required_if:referral_point,2,4,5'],
	'insurance_scheme' => ['required'],
	'insurance_id' => ['required_if:insurance_scheme,1'],
	'insurance_number' => ['required_if:insurance_scheme,1'],
	'date_recorded' => ['nullable', 'date'],
];

// I use a simple action in my controller's store() function:
CreatePatient::execute($request->validated());

But it tells me the Field relation_to_next_of_kin doesn't have a default value. I don't know what the problem is. When I dump the data, I get the value passed for that field.

0 likes
7 replies
zoidq's avatar

So it looks like the field relation_to_next_of_kin has a validated rule making it a required field however your app is still trying to create an entry without a value for that field.

Since the validation rule looks fine, can you be sure that the validator is being called?

What does the $request->all() output look like and how about $request->validated()?

Emokores's avatar

@zoidq Yes, it is a required field. When I dump using dd($request) the value for that field is passed. But I can't tell why it cannot reach the database.

Emokores's avatar

@zoidq I get this array with dd($request->all()):


[▼
  "name" => "Richard Jarvis"
  "email" => "[email protected]"
  "gender" => "M"
  "age_type" => "yo"
  "age" => "8"
  "dob" => "2014-04-13"
  "date_recorded" => "2022-09-23"
  "mobile_number" => "+1 (434) 993-2514"
  "mobile_number_2" => "+1 (299) 727-8296"
  "occupation" => "baby"
  "address" => "Quas consequatur Du"
  "nok_id" => "1"
  "relation_to_next_of_kin" => "2"
  "other_relation_to_next_of_kin" => null
  "referral_point" => "1"
  "referral_point_details" => null
  "other_referral_point_details" => null
  "insurance_scheme" => "0"
  "insurance_id" => null
  "insurance_number" => null
]

Tray2's avatar
Tray2
Best Answer
Level 73

You need to check your form, migration, validation and controller and see that you have spelled it the same way, and maker sure it's allowed for mass update in the model.

zoidq's avatar

@Tray2 Is the standard behaviour for fields which are not specified as fillable to be ignored/omitted?

Tray2's avatar

@zoidq Not sure, but it's worth checking since it obviously either fails the validation, or can't be set.

I suggest showing your model, controller, and a dd of the validated array.

Emokores's avatar

@Tray2 I got it! I misspelt the field relation_to_next_of_kin in the model as relation_to_nok. I keep making this mistake all the time. Thank you @tray2. I appreciate it.

1 like

Please or to participate in this conversation.