Search code examples
phplaravellaravel-5laravel-artisanartisan-migrate

Created a fresh database, now running any artisan command throws an error about a missing table


I wanted a fresh development database so I could seed with new data, so I manually dropped and recreated my development database and now running any artisan commands throws an error. I continuously get an error saying that I'm missing a table.

In Connection.php line 647:

  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydatabase.stores'   
  doesn't exist (SQL: select * from `stores`)                                   


In PDOConnection.php line 63:

  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydatabase.stores'   
  doesn't exist                                                                


In PDOConnection.php line 61:

  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydatabase.stores'   
  doesn't exist                                                                

I haven't run php artisan migrate:refresh in a long time so I'm not sure where the table stores is being used that's causing this error. Adding a -v flag doesn't provide any additional output to further trace the stack.

I've tried manually dropping the database and recreating it via the mysql. I've tried composer dump-autoload but that doesn't help either. I can't run php artisan migrate:install because calling ANY artisan command will throw the same error. Even calling php artisan throws the error. I've tried looking at my service providers to see if the table is being referenced in any of the constructors but I don't see it being used.

Is there anywhere in the code I should be checking for the use of this table? I'm not sure what is instantiated when php artisan is called.

The stores table is actually my first migration, so it's supposed to be the first thing created, but for some reason it's being called as a part of the artisan process.


Solution

  • As mentioned by @aynber in the comment to my question, the problem was several of my commands in the app/Console/Commands/* directory were instantiating an object in its constructor that referenced the Store model in its parent constructor. Specifically, it was running the line

    $this->storeId = Store::get()->last()->id;
    

    Commenting out this line allowed me to run my artisan commands.