Well this sounds like an issue to me in general. Why would you create your database after composer install? In general you want to have your server up and running before you install your application
composer dump-autoload and php artisan unknown table/database error
https://laracasts.com/discuss/channels/laravel/php-artisan-unknown-table-error-on-any-command
Hi all,
So i have created a laravel command which runs via cron, it first checks the DB for some data before running using a command like this.
$schedule->command('NewTest:test')
->when(!ScheduleHelper::hasRunToday));
Running "php artisan" or "composer dump-autoload" will throw errors if the DB does not exist or if a specific table does not exist yet.
This is an issue when i deploy to my hosting providers as the database does not exist yet until after the composer scripts have run including:
"post-autoload-dump": [
"Illuminate\Foundation\ComposerScripts::postAutoloadDump",
"@php artisan package:discover"
]
Does anyone know why "php artisan" command decides to load all dependencies even if its not running the command that actually hits the DB?
I have tried adding checks like this but the die method seems to kill the build and without that i just recieve errors stating the DB doesent exist! The code is not even running yet it is just building so there is no need for a DB connection to exist yet.
try {
DB::connection()->getPdo();
} catch (\Exception $e) {
die("Could not connect to the database. Please check your configuration.");
}
if (DB::connection()->getDatabaseName() && Schema::hasTable('scheduled_events')) {
//run my code
}
thanks
Please or to participate in this conversation.