Magento – Please Correct The Country Code error when viewing customer data

magento2.3.1

I keep getting this error in Magento 2.3.1 when viewing some customer address data in Customers > view customer > Addresses
"Something went wrong with processing the default view and we have restored the filter to its original state."

The error doesn't appear if the customer has not got an address saved.

Digging in to the exception.log file I see this error:

main.CRITICAL: Please correct the country code: . {"exception":"[object] (Magento\Framework\Exception\LocalizedException(code: 0): Please correct the country code: . at /var/www/magento/vendor/magento/module-directory/Model/ResourceModel/Country.php:46)"} []

It happens on all new customer accounts whether they've registered on the frontend of the site or created in admin.
The site has 3 store views (GBP, EUR and USD) and it happens on accounts created on all store views.
The migrated accounts from 1.9 aren't affected.
The grid at the bottom of the page never renders either. The spinner just spins.

Any ideas what might be causing this?
spinner

Best Answer

For me the issue was that for some reason in the "customer_address_entity" table some address entities were missing a value in the "country_id" field. This might've been due to an upgrade, but I can not tell for certain as I did not set up that particular shop.

The solution would be to just add the correct country code for each address. Since that particular shop only allowed customers from one country, it was a quite simple SQL query:

UPDATE customer_address_entity SET country_id = '<Your country code>' WHERE  country_id = '';
Related Topic