4.0 to 4.3 Upgrade Error. Please suggest

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 years ago
I can see the public store working fine without logging in as a user (admin). I can navigate through pages and every thing successfully.

The moment I login with my email and password, the error starts popping again.

This is happening with two different admin accounts.
3 years ago
New York wrote:
Yes im the admin and i can confirm that I can see the ShippingAddress_ID in the customer table with a valid value....
Is there a record in the CustomerAddresses table where its Address_Id = ShippingAddress_ID and Customer_Id =  the customer's Id?

CustomerService  GetCustomerAddress()
var query = from address in _customerAddressRepository.Table
                join cam in _customerAddressMappingRepository.Table on address.Id equals cam.AddressId
                where cam.CustomerId == customerId && address.Id == addressId
                select address;


Customer table has admin record with ID: 1 and ShippingAddress_ID: 167
Address table has a valid record with ID: 167
3 years ago
Use SQL to update your Customer record's ShippingAddress_Id to 0  (zero)
3 years ago
New York wrote:
Use SQL to update your Customer record's ShippingAddress_Id to 0  (zero)


There is no record in Address Table with ID 0.

Hence, when I ran this query:


Update [dbo].[Customer] SET ShippingAddress_ID = 0 WHERE  ID=1

It says

Msg 547, Level 16, State 0, Line 5
The UPDATE statement conflicted with the FOREIGN KEY constraint "Customer_ShippingAddress". The conflict occurred in database "localdb", table "dbo.Address", column 'Id'.
The statement has been terminated.

Can I try any other than 0?
3 years ago
Not sure if this would help, but in the original exception/error there is one line which shows in red color. My original post didn't retain the color so posting the image, just in case, if we are missing anything else apart from the initial error.

[url=https://ibb.co/wwjywYq][/url]
3 years ago
is there a duplicate of the combination Customer_Id = 1 and Address_Id = 167 in the table CustomerAddresses?

this would throw error for Queryable.Single Method

"Returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence."





mr.mourya wrote:
Yes im the admin and i can confirm that I can see the ShippingAddress_ID in the customer table with a valid value....
Is there a record in the CustomerAddresses table where its Address_Id = ShippingAddress_ID and Customer_Id =  the customer's Id?

CustomerService  GetCustomerAddress()
var query = from address in _customerAddressRepository.Table
                join cam in _customerAddressMappingRepository.Table on address.Id equals cam.AddressId
                where cam.CustomerId == customerId && address.Id == addressId
                select address;


Customer table has admin record with ID: 1 and ShippingAddress_ID: 167
Address table has a valid record with ID: 167
3 years ago
Yes, there are multiple records for Customer_ID 1 in CustomerAddresses table:

SELECT TOP (1000) [Customer_Id]
      ,[Address_Id]
  FROM [dbo].[CustomerAddresses] WHERE Customer_ID = 1

Customer_Id  Address_Id   Email ID
1                          24                   [email protected]
1                          143                 [email protected]
1                          148                [email protected]
1                          168                [email protected]

Strangely none of the above email IDs and addresses match what ID =1 in Customer Table has.

SELECT ID, Email, ShippingAddress_ID, * FROM [dbo].[Customer] WHERE ID = 1

ID  Email                                          ShippingAddress_ID
1  [email protected]                  167

Not sure, when were these duplicates got created and whats causing this whole issue during upgrade.
3 years ago
Ok, finally i figured out.

I had to run this query:

UPDATE Customer
SET Customer.BillingAddress_Id = NULL, Customer.ShippingAddress_Id = NULL
WHERE (Customer.BillingAddress_Id  IS NOT NULL
AND NOT EXISTS (SELECT 1
                   FROM CustomerAddresses
                   WHERE Customer.BillingAddress_Id = CustomerAddresses.Address_Id))
OR
(Customer.ShippingAddress_Id  IS NOT NULL
AND NOT EXISTS (SELECT 1
                   FROM CustomerAddresses
                   WHERE Customer.ShippingAddress_Id = CustomerAddresses.Address_Id))


Source:

https://www.nopcommerce.com/en/boards/topic/80047/nopcommerce-430-bug-fixes-and-improvements/page/6#264900

Thanks a ton, JonQuick! You made my day.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.