How do I run seeder on the test database on Ravel 9?

Asked 2 years ago, Updated 2 years ago, 325 views

I'm developing with Ravel 9+docker.

You are about to run db:seed to create initial or sample data.
This will create data in the development database.

I'm also trying to add initial and sample data to the test database, but I don't know how to do it.

In config/database, connections configures mysql for development and testing
I do not use .env.testing.

Thank you for your cooperation.

laravel

2022-10-09 01:00

1 Answers

It should be possible by specifying --database=testing as an option for the db:seed command.

However, depending on the test content, RefreshDatabase and InteractsWithDatabase::seed ($this->seed($seeder)) may be recommended for in-test. https://readouble.com/laravel/9.x/ja/database-testing.html

You should also be able to override the default DB connection by specifying the DB_CONNECTION environment variable, such as DB_CONNECTION=hoge./artisan fuga, when executing the arisan command that cannot be specified as an argument.


2022-10-09 01:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.