Issue with sales channel domain

Hi,

we want to delete a sales channel, but we are getting this error.

#1451 - Unable to delete or update parent line: a foreign key condition fails (‚test2‘.‚customer‘, CONSTRAINT ‚fk.customer.bound_sales_channel_id‘ FOREIGN KEY(‚bound_sales_channel_id‘) REFERENCES ‚sales_channel‘ (‚id‘) ON UPDATE CASCADE)

How can we resolve this issue?

You have customers that are assigned to that sales channel. You have either manually assign them to a other sales channel or you can do it via the database. Then you will be able to delete the sales channel (or a other FOREIGEN KEY error will appear and you have to do the same again).

yes… I did it via database . But once i started to update to 6.5, im getting another sales channel id foreign key exception .

Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (test.system_config, CONSTRAINT fk.system_config.sales_channel_id FOREIGN KEY (sales_channel_id) REFERENCES sales_channel (id) ON DELETE CASCADE ON UPDATE CASCADE)"

But i checked the DB before and after update , system_config table is not present. How can i solve this?

That is not possible. Shopware could not work without that table. The table structure looks like that:

CREATE TABLE `system_config` (
  `id` binary(16) NOT NULL,
  `configuration_key` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `configuration_value` json NOT NULL,
  `sales_channel_id` binary(16) DEFAULT NULL,
  `created_at` datetime(3) NOT NULL,
  `updated_at` datetime(3) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

ALTER TABLE `system_config`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq.system_config.configuration_key__sales_channel_id` (`configuration_key`,`sales_channel_id`),
  ADD KEY `fk.system_config.sales_channel_id` (`sales_channel_id`);

ALTER TABLE `system_config`
  ADD CONSTRAINT `fk.system_config.sales_channel_id` FOREIGN KEY (`sales_channel_id`) REFERENCES `sales_channel` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
COMMIT;

Thanks for the help. I did it.
I just removed the foreign keys for the updation purpose.

I have done:

alter table customer drop FOREIGN key fk.customer.bound_sales_channel_id;

alter table customer drop FOREIGN key fk.customer.sales_channel_id;

alter table newsletter_recipient drop FOREIGN key fk.newsletter_recipient.sales_channel_id;

ALTER table order drop FOREIGN key fk.order.sales_channel_id;

Alter table system_config drop FOREIGN key fk.system_config.sales_channel_id;

Then after updating :

ALTER TABLE customer
ADD CONSTRAINT fk.customer.bound_sales_channel_id
FOREIGN KEY (bound_sales_channel_id)
REFERENCES sales_channel (id);

ALTER TABLE customer
ADD CONSTRAINT fk.customer.sales_channel_id
FOREIGN KEY (sales_channel_id)
REFERENCES sales_channel (id);

ALTER TABLE newsletter_recipient
ADD CONSTRAINT fk.newsletter_recipient.sales_channel_id
FOREIGN KEY (sales_channel_id)
REFERENCES sales_channel (id);

ALTER TABLE order
ADD CONSTRAINT fk.order.sales_channel_id
FOREIGN KEY (sales_channel_id)
REFERENCES sales_channel (id);

ALTER TABLE system_config
ADD CONSTRAINT fk.system_config.sales_channel_id
FOREIGN KEY (sales_channel_id)
REFERENCES sales_channel (id);

And I was getting an error with System_config table:
ALTER TABLE system_config
ADD CONSTRAINT fk.system_config.sales_channel_id
FOREIGN KEY (sales_channel_id)
REFERENCES sales_channel (id);
MySQL reports: Documentation

#1452 - Cannot add or update child row: a foreign key condition fails (test.#sql-5f2_1252a, CONSTRAINT fk.system_config.sales_channel_id FOREIGN KEY (sales_channel_id) REFERENCES sales_channel (id ))

Static analysis:

1 errors were found during the analysis.

Undetected ALTER operation. (near „;“ at position 81)
SQL command: copy

ALTER TABLE system_config drop FOREIGN key fk.system_config.sales_channel_id;

MySQL reports: Documentation

#1064 - Error in SQL syntax. Please look up the correct syntax in the manual at ''fk.system_config.sales_channel_id' in line 1 alter table system_configdrop FOREIGN keyfk.system_config.sales_channel_id; MySQL reports: Documentation #1091 - DROP FOREIGN KEY: Cannot delete fk.system_config.sales_channel_id`. Does it exist?

How can i resolve this issue? And when I altered the tables
CONSTRAINT fk.customer.sales_channel_id FOREIGN KEY (sales_channel_id) REFERENCES sales_channel (id) , the column is updated like this, but i need
CONSTRAINT fk.customer.sales_channel_id FOREIGN KEY (sales_channel_id) REFERENCES sales_channel (id) ON UPDATE CASCADE . cascade part is not present.
Also for system_config table i need,
CONSTRAINT fk.system_config.sales_channel_id FOREIGN KEY (sales_channel_id) REFERENCES sales_channel (id) ON DELETE CASCADE ON UPDATE CASCADE , both update and delete cascade.
How i can solve this?

It looks like your tables are not complete anymore.

Download the Shopware version you have installed and then compare the database of the new installation with yours.

Hopefully you may can rebuild it then.