php – Laravel Artisan can talk to MySQL but Laravel web page cannot?-ThrowExceptions

Exception or error:

I have a new VM running ubuntu(16.04)/apache(2.4)/php(7.2)/mysql(5.7) and I have installed Laravel 5.5.latest.

I have set up db connection details in .env file. (which are correct as I can use them to connect in mysql on the command line)

Laravel artisan can talk to the DB because my migrations have worked (I can see the tables from mysql on the command line)

But Laravel web pages cannot access the db, complaining that table db_name.table_name does not exist.

I’ve put in some debug into the page and it dumps the correct .env db settings.

Any idea why the db works from Artisan on the CLI but not via web pages?

Stack trace:

[2020-01-07 22:48:07] local.ERROR: SQLSTATE[42S02]: 
Base table or view not found: 1146 Table 'SITE.property_types' doesn't exist
(SQL: select * from `property_types` where `parent_id` is null) 
{"exception":"[object] (Illuminate\\Database\\QueryException(code: 42S02):
 SQLSTATE[42S02]: Base table or view not found: 1146 
Table 'SITE.property_types' doesn't exist 
(SQL: select * from `property_types` where `parent_id` is null) at 
/vagrant/vendor/laravel/framework/src/Illuminate/Database/Connection.php:6 4, 
PDOException(code: 42S02): SQLSTATE[42S02]: Base table or view not found:
 1146 Table 'SITE.property_types' doesn't exist at 
/vagrant/vendor/laravel/framework/src/Illuminate/Database/Connection.php:326)

[stacktrace]
#0 /vagrant/vendor/laravel/framework/src/Illuminate/Database/Connection.php(624): Illuminate\\Database\\Connection->runQueryCallback('select * from `...', Array, Object(Closure))
#1 /vagrant/vendor/laravel/framework/src/Illuminate/Database/Connection.php(333): Illuminate\\Database\\Connection->run('select * from `...', Array, Object(Closure))
#2 /vagrant/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(1719): Illuminate\\Database\\Connection->select('select * from `...', Array, true)
#3 /vagrant/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(1704): Illuminate\\Database\\Query\\Builder->runSelect()
#4 /vagrant/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(481): Illuminate\\Database\\Query\\Builder->get(Array)
#5 /vagrant/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(465): Illuminate\\Database\\Eloquent\\Builder->getModels(Array)
#6 /vagrant/app/Http/Controllers/BaseController.php(101): Illuminate\\Database\\Eloquent\\Builder->get()
#7 /vagrant/app/Http/Controllers/BaseController.php(48): App\\Http\\Controllers\\BaseController->buildCategoryNav()
#8 /vagrant/app/Http/Controllers/StaticController.php(40): App\\Http\\Controllers\\BaseController->__construct(Object(App\\propertyArea), Object(App\\propertyType))
#9 [internal function]: App\\Http\\Controllers\\StaticController->__construct(Object(App\\Property), Object(App\\propertyArea), Object(App\\propertyType))
#10 /vagrant/vendor/laravel/framework/src/Illuminate/Container/Container.php(785): ReflectionClass->newInstanceArgs(Array)
#11 /vagrant/vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\\Container\\Container->build('App\\\\Http\\\\Contro...')
#12 /vagrant/vendor/laravel/framework/src/Illuminate/Container/Container.php(586): Illuminate\\Container\\Container->resolve('App\\\\Http\\\\Contro...', Array)
#13 /vagrant/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(732): Illuminate\\Container\\Container->make('App\\\\Http\\\\Contro...', Array)
#14 /vagrant/vendor/laravel/framework/src/Illuminate/Routing/Route.php(226): Illuminate\\Foundation\\Application->make('App\\\\Http\\\\Contro...')
#15 /vagrant/vendor/laravel/framework/src/Illuminate/Routing/Route.php(796): Illuminate\\Routing\\Route->getController()
#16 /vagrant/vendor/laravel/framework/src/Illuminate/Routing/Route.php(757): Illuminate\\Routing\\Route->controllerMiddleware()
#17 /vagrant/vendor/laravel/framework/src/Illuminate/Routing/Router.php(671): Illuminate\\Routing\\Route->gatherMiddleware()
#18 /vagrant/vendor/laravel/framework/src/Illuminate/Routing/Router.php(651): Illuminate\\Routing\\Router->gatherRouteMiddleware(Object(Illuminate\\Routing\\Route))
#19 /vagrant/vendor/laravel/framework/src/Illuminate/Routing/Router.php(635): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
#20 /vagrant/vendor/laravel/framework/src/Illuminate/Routing/Router.php(601): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
#21 /vagrant/vendor/laravel/framework/src/Illuminate/Routing/Router.php(590): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
#22 /vagrant/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
#23 /vagrant/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))
#24 /vagrant/vendor/fideloper/proxy/src/TrustProxies.php(56): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#25 /vagrant/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Fideloper\\Proxy\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#26 /vagrant/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#27 /vagrant/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(30): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#28 /vagrant/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#29 /vagrant/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#30 /vagrant/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(30): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#31 /vagrant/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#32 /vagrant/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#33 /vagrant/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#34 /vagrant/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#35 /vagrant/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#36 /vagrant/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(46): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#37 /vagrant/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#38 /vagrant/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#39 /vagrant/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#40 /vagrant/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#41 /vagrant/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#42 /vagrant/public/index.php(55): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#43 {main}
How to solve:

We had this issue today, and the solution turned out to be restarting php artisan serve after changing .env file.

If that doesn’t help, you can also try:

php artisan config:clear
php artisan config:cache

Leave a Reply

Your email address will not be published. Required fields are marked *