LoginSignup
1
0

More than 1 year has passed since last update.

CircleCiでテスト時にCaused by PDOException: SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "users" does not exist LINE 1:

Last updated at Posted at 2021-11-27

環境

laravel 6.20.37
phpuit 8.5.21

エラー内容

Caused by
PDOException: SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "users" does not exist
LINE 1: insert into "users" ("name", "email", "email_verified_at", "...
                    ^

原因

DatabaseTransactionsを使用していたことが原因のようでした。

AnswerControllerTest.php
use DatabaseTransactions;

RefreshDatabaseを使用することでエラーがなくなりました。

AnswerControllerTest.php
use Illuminate\Foundation\Testing\RefreshDatabase;

use RefreshDatabase;

RefreshDatabaseは各テストの後にデータベースをリセットできるので前のテストがその後のテストデータに影響しないのに対し、DatabaseTransactionsは各テストケースをデータベーストランザクションでラップしてデータベースをリセットするという違いがあるようです。

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0