I update schema newsletter_subscriber, certain I added firstname column which is a foreign key to customer_entity firstname, and when I post data the object with value is sent and in Magento insert method values are translated to "?", and then it throws the error.

Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`magento`.`newsletter_subscriber`, CONSTRAINT `NEWSLETTER_SUBSCRIBER_FIRSTNAME_CUSTOMER_ENTITY_FIRSTNAME` FOREIGN KEY (`firstname`) REFERENCES `customer_entity` (`firstname`) ON DELETE SET NULL), query was: INSERT INTO `newsletter_subscriber` (`store_id`, `change_status_at`, `subscriber_email`, `subscriber_status`, `firstname`, `firstname`) VALUES (?, '2019-02-12 15:35:20', ?, ?, ?, ?)


Upgrade schema

                $setup->getFkName('newsletter_segment', 'firstname', 'customer_entity', 'firstname'),


<field name="firstname">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="visible" xsi:type="boolean">true</item>
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="source" xsi:type="string">subscriber</item>
                    <item name="label" xsi:type="string">Firstname</item>


When I post null value for the first name, a record is saved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.