Resolved: how to solve this error
ALTER TABLE sales ADD FOREIGN KEY (customer_id) REFERENCES customers(customer_id) ON DELETE CASCADE
Error Code: 1822. Failed to add the foreign key constraint. Missing index for constraint 'sales_ibfk_1' in the referenced table 'customers'
Thanks for reaching out.
The error suggests that the `customer_id` field in the `customers` table is not indexed. To fix this, you need to create an index on `customer_id` in the `customers` table before you can add a foreign key constraint that references it.
Hope this helps.