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

vogtdominik's avatar

php artisan migrate causes QueryException because of unknown column

Hello everyone, so im struggeling with finding out, how to fix the "php artisan migrate" command to skip any registered commands inside the ..\Console\Kernel Class.

The scenario is as follows. I have a Console Command ChargeAdvertisement which is called periodically and has to the $commands Array inside the Kernel class.

ChargeAdvertisement is going to get all ACTIVE Advertisements, where being active is defined inside a scope function.

I want to apply a change to Advertisement.class to make it pausable. So i create a new migration file and add a column paused to the advertisements table. I am also going to change the active scope function, adding the where condition

public function scopeActive($scope){
  $scope->where('published_date', '>', DB::raw('NOW()')) 
    ->where('paused', 0); // this is new
}

Now this is where I'm getting stuck. When I push it to production and call php artisan migrate, I get an QueryException telling me that paused is not defined in advertisements table.

So ideally I want php artisan migrate to skip any Console Commands, that are defined inside the Kernel Class. Where do I do this? Or what is the alternative, besides commenting stuff out.

0 likes
4 replies
vogtdominik's avatar

So one solution I came up with, is to add a try/catch block around the dangerous part.

Randolf's avatar

I had a similar problem. In a view composer, I created a table, get data from that and all works correct. But when I reset/refresh migrations, fails because the table doesn´t exist.

So, my solution was check if the table exists... In your case:


use Illuminate\Support\Facades\Schema;

//check if advertisements table has paused column
public function scopeActive($scope)
{
    if(Schema::hasColumn('advertisement', 'paused')) 
    {   
        $scope->where('published_date', '>', DB::raw('NOW()')) 
            ->where('paused', 0); // this is new
    }
}

I didn´t tryed, but it´s a idea...

vogtdominik's avatar

Thats also a good idea. Still a lot of overhead if i want to adapt that in every scenario.

Does anyone know why all commands are run in the first place?

Snapey's avatar

artisan bootstraps the framework. You must have something accessing your model. It it because it's a global scope and you have a view composer with a wildcard that uses the model?

Please or to participate in this conversation.