Entity base field requires value despite setRequired(FALSE) I have set a field in my entity to not required using  

-&gt;setRequired(FALSE)


However when I then leave the field blank and try to save the entity I get this error

The website encountered an unexpected error. Please try again later.

Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'category' cannot be null: INSERT INTO {myentity_field_data} (id, langcode, uid, question, category, runtime, anonymous_vote_allow, cancel_vote_allow, result_vote_allow, status, created, default_langcode) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11); Array ( [:db_insert_placeholder_0] =&gt; 1 [:db_insert_placeholder_1] =&gt; en [:db_insert_placeholder_2] =&gt; 1 [:db_insert_placeholder_3] =&gt; test [:db_insert_placeholder_4] =&gt; [:db_insert_placeholder_5] =&gt; 0 [:db_insert_placeholder_6] =&gt; 1 [:db_insert_placeholder_7] =&gt; 1 [:db_insert_placeholder_8] =&gt; 1 [:db_insert_placeholder_9] =&gt; 1 [:db_insert_placeholder_10] =&gt; 1442607827 [:db_insert_placeholder_11] =&gt; 1 ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage-&gt;save() (line 930 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).


So is this a result of setRequired or some failure of my entity reference?
Your field was likely created in the database with setRequired(TRUE) which means your field cannot contain NULL values. If you change your field to setRequired(FALSE), then NULL values will be allowed.

Inspect your *_field_data table and check if the field schema IS_NULL = TRUE, if not, then you will need to update your field schema by running an update hook. See Write update functions for entity schema updates for information on how to update your entity schema.

If you have not deployed your module anywhere other than locally then it should be safe to modify your database directly without creating an update hook.