Empty relation field validation failed with Guest Entries plugin I am trying to save a entry with the Guest Entries plugin.

The entry has a custom field 'office' thats set to 'entry' a relation to section 'offices'.

&lt;fieldset class="form-fieldset row-spacing-2"&gt;
    &lt;select class="form-input form-select" name="fields[office][]"&gt;
        &lt;option&gt;Select office&lt;/option&gt;
        {% for office in craft.entries.section('offices') %}
            &lt;option value="{{ office.id }}"&gt;{{ office.title }}&lt;/option&gt;
        {% endfor %}    
    &lt;/select&gt;
&lt;/fieldset&gt;


The field is set to required in the CP. When I save it with the field set it works, but when empty it throws this error:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails


Can this error be caught or am i doing something wrong here?

Thanks in advance!
It looks like it's doing what it should. When you set a field to 'required', you are basically telling the system to not let the entry be saved if you haven't filled out the field you've set 'required' on. That's what this error saying (albeit at a database level). 

Two quick solutions as I see it...


Always make sure you have a default value that can be used for this
field. So you aren't violating the 'required' setting.
Remove the 'required' option from the field in the CP.


EDIT: In the Plugin settings in the CP, have you turned on the Validate Entry lightswitch for the section you are adding to on the front end? Only I've just had a quick play around with the plugin myself, and I get a validation error when I don't submit an entryId for the related section on the front end form. So it looks as though it's working as expected.

I used this to get the errors...

{%for error in guestEntry.getAllErrors %}
    {{ error }}
{% endfor %}


I also just used the default config file guestEntries.php as suggested in the README...

&lt;?php

return array(
    'entryVariable' =&gt; 'guestEntry',
);