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

ChrisF79's avatar

Error log saying no query results found but there are records

I just don't understand this error. I'm working on an app where I download records from a server and store them in a temporary table called rets_property_res_naples and then in a console command, they get selected, transformed a bit, then put into a "master" table.

I'm now getting the below error and I just don't understand it. If I go into php artisan tinker and do a \App\Models\TempListingNaples::all(), I get all of the records!

Like I said, I just don't understand so why would it pull fine from the model but the console command couldn't?

Error Message

Illuminate\Database\Eloquent\ModelNotFoundException: No query results for model [App\Models\TempListingNaples]. in /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:454
Stack trace:
#0 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php(85): Illuminate\Database\Eloquent\Builder->firstOrFail()
#1 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php(55): App\Jobs\ProcessListing->restoreModel(Object(Illuminate\Contracts\Database\ModelIdentifier))
#2 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Queue/SerializesModels.php(45): App\Jobs\ProcessListing->getRestoredPropertyValue(Object(Illuminate\Contracts\Database\ModelIdentifier))
#3 [internal function]: App\Jobs\ProcessListing->__wakeup()
#4 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(42): unserialize('O:23:"App\Jobs\...')
#5 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(88): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\SqsJob), Array)
#6 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(327): Illuminate\Queue\Jobs\Job->fire()
#7 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(277): Illuminate\Queue\Worker->process('sqs', Object(Illuminate\Queue\Jobs\SqsJob), Object(Illuminate\Queue\WorkerOptions))
#8 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(118): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\SqsJob), 'sqs', Object(Illuminate\Queue\WorkerOptions))
#9 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(102): Illuminate\Queue\Worker->daemon('sqs', 'ImportQueue', Object(Illuminate\Queue\WorkerOptions))
#10 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(86): Illuminate\Queue\Console\WorkCommand->runWorker('sqs', 'ImportQueue')
#11 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#12 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#13 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#14 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#15 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(576): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#16 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Console/Command.php(183): Illuminate\Container\Container->call(Array)
#17 /srv/www/listingnaples.com/vendor/symfony/console/Command/Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#18 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Console/Command.php(170): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#19 /srv/www/listingnaples.com/vendor/symfony/console/Application.php(921): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 /srv/www/listingnaples.com/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 /srv/www/listingnaples.com/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Console/Application.php(90): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(133): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 /srv/www/listingnaples.com/artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 {main}

Here is the model:

TempListingNaples

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class TempListingNaples extends Model
{
    protected $table = "rets_property_res_naples";
    protected $hidden = ['created_at', 'updated_at'];
    protected $dates = ['PhotoModificationTimestamp'];
    public $board = "Naples";

    public function __construct(array $attributes = [])
    {
        $this->fillable = \Config::get('master_schema');
        parent::__construct($attributes);
    }
    
    function toArray()
    {
        $temp = parent::toArray();
            if(starts_with($temp['PhotoModificationTimestamp'], '-'))
            {
                $temp['PhotoModificationTimestamp'] = '0000-00-00 00:00:00';
            }
        return $temp;
    }
}

Console Command

<?php
namespace App\Console\Commands;

use DB;
use App\Models\Listing;
use App\Models\ListingMigrator;
use App\Models\TempListingNaples;
use App\Models\RetsFeed;
use Illuminate\Console\Command;

class MigrateListings extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'chores:MigrateListings';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Migrate the listings from each boards temp table to rets_property_res_mstr';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        // Turn off query logging
        DB::connection()->disableQueryLog();

        // get each feed so we can assign models
        $feeds = RetsFeed::where('active', '=', 1)->get();

        foreach ($feeds as $feed)
        {

            // Define which model to use based on the feed's board using the fully qualified namespace
            $class = 'App\Models\TempListing' . $feed->board;

            // Get the listings sitting in the temp table for that board
            $listings = $class::orderBy('MatrixModifiedDT','asc')->get();

            $listings->each(function($listing) use ($feed) {
                \App\Jobs\ProcessListing::dispatch($listing, $feed);
            });

        }
    }
}
0 likes
9 replies
Talinon's avatar
Talinon
Best Answer
Level 51

@chrisf79 You are dispatching the job into a queue - have you restarted your queue worker(s) since the last code change?

To quote the Laravel documentation:

Remember, queue workers are long-lived processes and store the booted application state in memory. As a result, they will not notice changes in your code base after they have been started. So, during your deployment process, be sure to restart your queue workers.

ChrisF79's avatar

Rebooting now to see if it fixes it... Just rebooted and it is doing the exact same thing... it's just that error over and over.

Talinon's avatar

@chrisf79

$class = 'App\Models\TempListing' . $feed->board;

Maybe add the preceding slash?

$class = '\App\Models\TempListing' . $feed->board;
Snapey's avatar

throw in a composer dump autoload if you have been changing classnames

ChrisF79's avatar

I just emptied the entire Amazon SQS queue and it seems to be working now! Could this error message just be saying, "Hey man... this job you want me to do... the record isn't in that model."

Jaytee's avatar

No so what happens is, when you dispatch Jobs, it takes essentially the whole class/models and serializes them, then saves it in the database. Then when the job is run, is unserializes it from the database and builds that class up.

Remember, jobs are used to do stuff later on right? So if you think about it, we need a way to save the state of that class at that current time that we were dispatching the job, so that our application can continue executing everything else.

So whenever you make a change to those classes, it won't reflect, because the queue is still using values from the database. So that's why we flush the queue.

In general, it's good practice to flush the queue everytime you make a change to a class that is in use by a queue, UNLESS you know it isn't going to interfere with the job (e.g: adding a method, that the job doesn't use is fine).

ChrisF79's avatar

That's very helpful and thanks everyone for taking the time out to help me!

Jaytee's avatar

No worries dude, however I believe @talinon should have best answer for this. I was just explaining how jobs work and why you may receive errors :)

Talinon's avatar

If you're using the SerializesModels trait, only the id of the eloquent model will be serialized. When the queue is run, Laravel will automatically retrieve the model from the database by the id.

You might want to consider ignoring missing models. You can read more about that here:

https://laravel.com/docs/5.8/queues#ignoring-missing-models

Please or to participate in this conversation.