laravel5でdbトランザクションをしようとしてるのですが、
なぜか502 Bad Gatewayとnginxのエラーが出てしまいます。
正常にtransaction処理をしてレコードを一件追加したいです。
あくまでやりたいことは複数テーブルの同時更新なのですが、
原因把握するために以下単純処理で試験してます。
処理
php
1DB::beginTransaction(); 2 $test = \App\Test::create(); 3 $test->user_id = 5; 4 $test->save(); 5DB::commit();
vi App/Test.php
php
1 2namespace App; 3use Illuminate\Database\Eloquent\Model; 4class Test extends Model 5{ 6}
table定義
MySQL
1 CREATE TABLE `tests` ( 2 `id` int(10) unsigned NOT NULL AUTO_INCREMENT, 3 `user_id` int(10) unsigned NOT NULL, 4 `created_at` timestamp NULL DEFAULT NULL, 5 `updated_at` timestamp NULL DEFAULT NULL, 6 PRIMARY KEY (`id`), 7 UNIQUE KEY `uniq` (`user_id`) 8) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
testsテーブルは空にした状態で
上記処理をおこなったところ
502 Bad Gatewayとなります。
以下トランザクション処理を削除すると問題なく処理できます。
php
1DB::beginTransaction(); 2DB::commit();
mysqlのerror_logには何もはかれていませんでした。
以下でcatchしようとしましたが502 Bad Gatewayとなりcatchができませんした。
try { DB::beginTransaction(); $test = \App\Test::create(); $test->user_id = 5; $test->save(); DB::commit(); } catch (Exception $e) { echo $e->getMessage(); }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。