wipe_data
There is a problem with this function
This wipe_data
Function my database cleans and manages data insertion
But this function shows error:
No active transactions
This is my code:
function wipe_data() { DB::beginTransaction(); $adminData = User::where('role', 'admin')->first(); try { User::truncate(); User_details::truncate(); User_kyc::truncate(); Token::truncate();`enter code here` $auto_id = date('Y'); DB::statement("ALTER TABLE ls_users AUTO_INCREMENT = $auto_id"); $admin = new User(); $admin->username = $adminData->username; $admin->email = $adminData->email; $admin->password = $adminData->password; $admin->role = $adminData->role; $admin->save(); $user_id = User::where('role', 'admin')->value('id'); DB::commit(); } catch (\Exception $ex) { DB::rollback(); return false; } return true; }
There are some statements that cause an implicit commit , including the
ALTER TABLE
statement you are using.So, before calling
DB::commit()
, your statement has already been committed, so the error occurred.