Menu

Soft Deletes vs. Unique Constraints: The Duplicate SKU Bug That Hid for a Year
📰

Soft Deletes vs. Unique Constraints: The Duplicate SKU Bug That Hid for a Year

DEV Community: laravel·Tuğrul Yıldırım·8 days ago
#oRoNeVpQ
#devtolaravel#devto#dev#unique#table
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.