magento2: Magento_Sales module fails to upgrade (email has a wrong format)
Preconditions
- Magento 2.2.3
- PHP 7.1.16
- MariaDB 10.2.9
Steps to reproduce
- composer update 2.2.3 to 2.2.4
- upgrade Magento_Sales data: current version - 2.0.7, required version - 2.0.9
Expected result
- update ok
Actual result
- upgrade logs : Module ‘Magento_Sales’: Upgrading data… We can’t save the address: Email has a wrong format
In which table should I fix emails ? I have email Null values with the following request
SELECT * FROM `sales_order_address` where email is NULL
SELECT * FROM `sales_order_address` where email is null
SELECT * FROM `quote_address` where email is null ORDER BY `created_at` DESC
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 6
- Comments: 36 (3 by maintainers)
It was related to null entry email in sales_order_address. resolved by
@kamranmalikawan The solution from @gtlt worked for me, but it did not work at first. We are running Magento 2 Commerce and got their support to help me with a solution. Here is what I ended up doing:
and 2. above I had a handful of emails that were not email addresses at all and fixed these up. Having already done @gtlt solution on NULL values, I had already replaced my NULL emails with noemail@foo.com. It should work with a NULL value if all rows are correct, but I can’t be 100% sure. For me having a dummy email is ok.
I ran the following sql to make sure all my NULL values had dummy emails
After the above, everything upgraded and deployed smoothly. In short, just make sure all the data in the email column are valid email addresses. Hope this helps!
For missing email addresses, I’ve combined two approaches above to use the order email address where available and otherwise use a dummy address:
But why do we have this issue while upgrading to 2.2.4. In my case all rows in
sales_order_addresstable havenullvalue inemailcolumn. Is theemailcolumn newly added in the upgrade? Setting dummy email to the record doesn’t seem correct. What is the correct way? @magento-engcom-team@gtlt To check all email fields on special characters or other symbols, i did this. Because I got ‘Invalid email format’ and searched my ass off when i treid to setup:upgrade
I used the update query to update rows with multiple the same issues
SELECT * FROM quote_address WHEREemailNOT REGEXP '^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$';SELECT * FROMsales_order_addressWHEREemailNOT REGEXP '^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$';UPDATEquote_addressSETemail= REPLACE(email, '', '');UPDATEsales_order_addressSETemail= REPLACE(email, '', '');@magento-engcom-team @engcom-backlog-nazar @gtlt The problem persists in magento 2.2.5, issue appears to be inconsistent code:
In
\Magento\Sales\Setup\UpgradeData::upgrademethod:method
\Magento\Sales\Setup\UpgradeData::fillQuoteAddressIdInSalesOrderAddresssets thequote_address_idinsales_order_address; the code saves to the database the entity\Magento\Sales\Model\Order\Addresswhich in turn relies on\Magento\Sales\Model\Order\Address\Validator::validateto apply validation by the resource model.It’s
\Magento\Sales\Model\Order\Address\Validatorthat enforces the valid email check. However\Magento\Sales\Setup\UpgradeSchemadoes NOT change thesales_order_address.quote_address_idcolumn, it IS STILL nullable.So why is
\Magento\Sales\Setup\UpgradeData::fillQuoteAddressIdInSalesOrderAddressnecessary when the column it affects is still nullable? Is the column not supposed to be nullable under any condition?Magento team please clarify. Thank you.
It appears to happen to people who have migrated from Magento 1. If you open it up as a ticket on the data migration tool repository he will say everything migrated correctly and it is a problem with the upgrade script.
@gtlt solution worked for me too. Just make sure you rm -rf var/cache/* rm -rf var/page_cache/* rm -rf generated/code/* Before running the magento setup:upgrade again
I was affected by this issue too.
Solution from gtlt resolved this issue. But I also agree with @webspeaks, setting a dummy email address should not be the correct solution.