Marco Marco - 10 months ago 181
MySQL Question

Laravel - General error: 1366 Incorrect integer value

When I try to save or update a model, I get an error that is below, for the field spid_id. I am not sure what is wrong.

General error: 1366 Incorrect integer value: '' for column 'spid_id'
at row 1 (SQL: update
= ,
2016-10-21 08:28:46,
= where
= 8)

This is how my table looks:

Schema::create('magazines', function (Blueprint $table) {

I tried to change my spid_id to not be nullable in the DB, by making a migration, because I thought that might be a reason:

Schema::table('magazines', function (Blueprint $table) {

But the field still remained nullable.

This is my store function for create form:

$magazine = Magazine::create([
'name' => $request->input('name'),
'visio_link_prefix' => $request->input('visio_link_prefix'),
'spid_id' => $request->input('spid_id'),
'summary' => $request->input('summary'),

Answer Source

You need to check spid_id exist in your request before you save it. For example in your case it will looks like:

'spid_id' => $request->has('spid_id') ? $request->input('spid_id') : NULL,