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

dan3460's avatar

Table Not found

I'm updating an old program, created a test database and run the migration. It crashed because of a table name on a foreign id:

           $table->boolean('clearance_customer')->default(false);
            $table->foreignId('sales_people_id')->constrained();
            $table->boolean('active')->default(true);

On the migration the table was named "sales_people", i changed the name of the table to "sales_peoples" including the name of the migration file.

Run the migration again and passed. My problem is that now when i run a job that update the sales people, i get an error that the table could not be fund.

 Bus::dispatch(new UpdateSalesPeople())
[!   Illuminate\Database\QueryException  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test.sales_people' does
n't exist (Connection: mysql, SQL: update `sales_people` set `active` = 0, `sales_people`.`updated_at` = 2025-05-12 11:45
:32).
] Aliasing 'UpdateSalesPeople' to 'App\Jobs\UpdateSalesPeople' for this Tinker session.

Where is the table name being cached?

0 likes
9 replies
krisi_gjika's avatar

how are you running this update query? Do you have a model for this table?

if so what does (new YourModel)->getTable() give?

dan3460's avatar

I'm using tinker to run the job:

 Bus::dispatch(new UpdateSalesPeople())

in tinker i run your function:

$ php artisan tinker
Psy Shell v0.12.8 (PHP 8.2.3 — cli) by Justin Hileman
> (new SalesPeople)->getTable()
[!] Aliasing 'SalesPeople' to 'App\Models\SalesPeople' for this Tinker session.
= "sales_people"
Shivamyadav's avatar

@dan3460 make sure to close the tinker after you made any changes and start it again then it will work and your table not found error will be resolved

dan3460's avatar

I did, that was the first thing that i thought was wrong. I have started a new shell call tinker and got the same result.

Shivamyadav's avatar

@dan3460 man I have found the issue .. Your table name is different in your migration your table name is sales_peoples and by default Laravel is looking for table in your test database with name sales_people ..

To solve it you can do these 2 things.

  1. Change your migration table name what Laravel is looking for.

2.Add a protected $table property set it to the table name which is sales_people..

protected $table = 'sales_peoples';
dan3460's avatar

Trying to follow the Laravel standard. When i create a model and migration:

php artisan make:model SalesPeople -m

Laravel creates the model SalesPeople and the table on the migration sales_peoples, in that way when I create a foreign id "sales_people_id" Laravel knows that the key field should be "sales_peoples.id". Is this correct?

I'm trying not to use the protected table option, i want it to be standard.

JussiMannisto's avatar
Level 50

@dan3460 People is a plural. You should use a singular form on models, e.g. SalesPerson. In fact, Laravel would automatically pluralize it to people, and the resulting table name would be sales_people.

dan3460's avatar

ok, now i complete confused. I changed the table name to what it was originally. Now the migration fails because is looking for a foreign id on a table called sales_peoples:

  SQLSTATE[HY000]: General error: 1824 Failed to open the referenced table 'sales_peoples' (Connection: mysql, SQL: alter table `locations` add constraint `locations_sales_people_id_foreign` foreign key (`sales_people_id`) references `sales_peoples` (`id`))

i did a global search for the word sales_peoples and is not were to be found.

dan3460's avatar

Got it now - SalesPerson. I don't know how is working on the production environment. I going to need to make several tests and change the database manually.

Thanks for the help.

Please or to participate in this conversation.