Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

akilrajdho's avatar

Problem With DB Transactions

Hi, I was having a strange problem while testing transactions. Within a transaction block I perform 3 database inserts, I insert one record in a Purchase table, one record in purchase_details table and one record in purchase_payments record. On purpose i changed one of the columns in the purchase_payments table from invoice_id to invoice_ids just to make sure that the whole transaction would fail. Then I tried to insert a purchase and surely enough not a single record was inserted in any of my 3 tables. Without reloading the browser i tried to save the purchase 3 times (through an ajax call) . Each of the times in the response body i got an exception Illuminate\Database\QueryException which is fair enough. Not a single record was inserted in the database. However when I changed back the column from invoice_ids to invoice_id and retried to save the purchase the record was saved 4 times. Somehow laravel remembered the 3 failed attempts and re-executed them as well. My database and tables all use the InnoDB engine. Has anyone dealed with this problem before?

0 likes
2 replies
mstnorris's avatar

I haven't personally experienced this before. Please could you post your code that causes this and then we can see if we can replicate it.

anandmainali5's avatar

@akilrajdho May be you must try "php artisan migrate:refresh" after you change the column name from invoice_id to invoice_ids.

Please or to participate in this conversation.