Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tobyreed's avatar

"$this->artisan('db:seed');" not seeding properly!

Hello everyone,

I am starting to use Laravels HTTP requests to test our back end API. However, I am running into an issue that I understand but am unable to fix.

The issue:

1) Tests\Unit\WorkspaceListTest::testListWorkspaces
Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such table: main.user (SQL: insert into "collections" (blah blah blah)

First off, the database is not meant to be main and the table is meant to be users and not user! It seems as if the database is not being seeded properly, but I have no idea why :/

The stack trace leads me back to this line of code:

$this->artisan('db:seed');

If anyone could help me understand the underlying problem and possibly help fix this I would be very grateful as I have been stuck on this for quite some time!

Thank you! :)

0 likes
9 replies
ftiersch's avatar
ftiersch
Best Answer
Level 28

Does your seeder work if you call it in the console with php artisan db:seed?

1 like
tobyreed's avatar

Weird, no it doesn't! Thank you I will check if this works after I have got the seeding to work first!

tobyreed's avatar

Back again, after clearing up the issue of the database not seeding properly when trying to run "php artisan db:seed" I tried running the test again and I got the exact same issue ??

1) Tests\Unit\WorkspaceListTest::testListWorkspaces
Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such table: main.user (SQL: insert into "collections" (blah blah blah)

I am really confused!

ftiersch's avatar

That is weird. Do you have changed settings for a testing environment somewhere that might change for example the database name? Like in the phpunit.xml?

tobyreed's avatar

From what I understand, no. Nothing that changes the database name

munazzil's avatar

Can you check your .env file and also config/app.php database name and password?, because this error came from connection to the database.

tobyreed's avatar

Yes, by the looks of it everything is correct.

tobyreed's avatar

I have a phpunit.xml that has the environment for the database

Back2Lobby's avatar

I faced same issue and I fixed it.

The problem was with the name of my relationship table in migrations.

Before: $table->foreignId("creator_id")->constrained("user");

After: $table->foreignId("creator_id")->constrained("users");

Make sure you rerun migrations after this change to have effect

Please or to participate in this conversation.