A product manager once asked me a simple question: "Why does the warehouse screen show two different products with the same SKU?"
I was sure it was impossible. The products table had a unique index on sku . The form validated uniqueness. We had tests. And yet, there they were: two active rows, same SKU, different prices, each one collecting its own stock movements for months.
The bug was not in a controller or a query. It was in a single line of a migration that looked perfectly reasonable in code review. This post is the story of that line, why it fails, and the patterns I now use whenever soft deletes and uniqueness meet in a Laravel business app.
The problem: soft deletes and unique keys disagree
Soft deletes are almost mandatory in ERP and CRM systems. You rarely want to physically delete a product, a customer or a supplier, because invoices, orders and audit logs still point at it.…