Delete a relation in frontend form We have a change profile page where members can choose out of the users table who of the other members is their mother (or father).

Below my (simplified) user profile form

&lt;form method="post" accept-charset="UTF-8" enctype="multipart/form-data"&gt;
&lt;script&gt;$(':checkbox').checkboxpicker();&lt;/script&gt;
{{ getCsrfInput() }}
&lt;input type="hidden" name="action" value="users/saveUser"&gt;
&lt;input type="hidden" name="redirect" value="leden/wijzig-profiel?m=updated"&gt;
&lt;input type="hidden" name="userId" value="{{ currentUser.id }}"&gt;
&lt;input type="hidden" name="fields[mother][]" value=""&gt;

&lt;label for="mother"&gt;{{ 'mother'|t }}&lt;/label&gt;
&lt;select name="fields[mother][]" &gt;
    &lt;option value=""&gt;There is no mother&lt;/option&gt;
    {% for mother in mothers %}
    &lt;option value="{{ mother.id }}"&gt;{{ mother.name }}&lt;/option&gt;
    {% endfor %}
    {% for user in users %}
    &lt;option value="{{ user.id }}"&gt;{{ user.name}}&lt;/option&gt;
    {% endfor %}    
&lt;/select&gt;
&lt;input type="submit" value="{{ 'Save'|t }}" name="proceed" &gt;




I've tried to empty the field mother but that results in a CDbException error.

CDbCommand faalde tijdens het uitvoeren van volgend SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`familywebsite`.`craft_relations`, CONSTRAINT `craft_relations_targetId_fk` FOREIGN KEY (`targetId`) REFERENCES `craft_elements` (`id`) ON DELETE CASCADE). The SQL statement executed was: INSERT INTO `craft_relations` (`fieldId`, `sourceId`, `sourceLocale`, `targetId`, `sortOrder`, `dateCreated`, `dateUpdated`, `uid`) VALUES (:row0_col0, :row0_col1, NULL, :row0_col3, :row0_col4, :row0_col5, :row0_col6, :row0_col7), (:row1_col0, :row1_col1, NULL, :row1_col3, :row1_col4, :row1_col5, :row1_col6, :row1_col7). Bound with :row0_col0='136', :row0_col1='1', :row0_col3='', :row0_col4=1, :row0_col5='2016-10-08 09:54:35', :row0_col6='2016-10-08 09:54:35', :row0_col7='e4211e99-5bbd-46c1-b703-c44e82bc4667', :row1_col0='136', :row1_col1='1', :row1_col3='2409', :row1_col4=2, :row1_col5='2016-10-08 09:54:35', :row1_col6='2016-10-08 09:54:35', :row1_col7='c0fb9927-89f1-4993-ba26-bc47a63bdc50'


This I can understand because the mother is a relation of the user, and by clearing the mother field value, it probably does not delete the relation and it will give and error like it does.

So question is how to delete the relation with mother field?
I believe you're getting that error because you're supplying an array ([]) for the mother field and the only value in that array would be an empty string ("") if they select the There is no mother option. So what Craft is attempting to save as a relation is [""]. Instead of an array of integer ID numbers, it's getting an empty string which isn't a valid value.

Even if you remove the value attribute of the option tag for the There is no mother option, the field will use the inner text of the tag as the value, so this does not solve your problem either.

One suggestion would be to use radio buttons instead and do the following:

&lt;label&gt;&lt;input type="radio" name="" value=""&gt; There is no mother&lt;/label&gt;
{% for mother in mothers %}
    &lt;label&gt;&lt;input type="radio" name="fields[mother][]" value="{{ mother.id }}"&gt; {{ mother.name }}&lt;/label&gt;
{% endfor %}
{% for user in users %}
    &lt;label&gt;&lt;input type="radio" name="fields[mother][]" value="{{ user.id }}"&gt; {{ user.name }}&lt;/label&gt;
{% endfor %}


This will keep the field empty if someone selects the There is no mother option.