wipe_data这个函数有问题
这个 wipe_data 功能我的数据库清理和管理数据插入
但这个函数显示错误:
没有活跃的交易
这是我的代码:
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;
} Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
有一些语句导致隐式提交,包括您正在使用的
ALTER TABLE语句。因此,在调用
DB::commit()之前,您的语句已经被提交,因此发生了错误。