mercredi 28 mars 2018

Laravel 5 - Update an integer value as NULL when it has a foreign key set

I'm updating a row in a table that in the migration is set up:

$table->integer('assigned_to')->unsigned()->nullable();

This row doesn't need to be assigned to a user so when creating the row the field is set as 'NULL'.

I'm now doing an update method where either a user id will be passed to the field or a null value if I wan't to 'un assign' the row.

Im getting an error regarding the foreign key (obviously...)

Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails

Is there anyway around this apart from removing the foreign key?



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

Aucun commentaire:

Enregistrer un commentaire