Laravel Version
9.52.16
PHP Version
8.1.4
Database Driver & Version
MySQL
Description
2023_04_08_065850_create_business_categories_table
don’t even exist in any of the migrations folder but still migrate command is trying to run this migration using custom artisan command php artisan migrate:multiple
that I have created to run migrations from multiple folders in specific sequence.
Error
public_html$ php artisan migrate:multiple
INFO Preparing database.
Creating migration table ............................................................................................................... 13ms DONE
INFO Running migrations.
>>>>>>>>> Above Migrations of othe folders ran fine here
INFO Running migrations.
2023_04_07_065850_create_business_categories_table ..................................................................................... 30ms DONE
2023_04_08_065850_create_business_categories_table ...................................................................................... 1ms FAIL
Illuminate\Database\QueryException
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'business_categories' already exists (SQL: create table `business_categories` (`id` char
(36) not null, `name` varchar(255) not null, `deleted_at` timestamp null, `created_at` timestamp null, `updated_at` timestamp null) default character set
utf8mb4 collate 'utf8mb4_unicode_ci')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:760
756▕ // If an exception occurs when attempting to run a query, we'll format the error
757▕ // message to include the bindings with SQL, which will make this exception a
758▕ // lot more helpful to the developer instead of just the database's errors.
759▕ catch (Exception $e) {
➜ 760▕ throw new QueryException(
761▕ $query, $this->prepareBindings($bindings), $e
762▕ );
763▕ }
764▕ }
+9 vendor frames
10 Modules/BusinessService/Database/Migrations/2023_04_08_065850_create_business_categories_table.php:21
Illuminate\Support\Facades\Facade::__callStatic()
+25 vendor frames
36 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
app\Console\Commands\RunMultipleMigrations.php file
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class RunMultipleMigrations extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature="migrate:multiple";
/**
* The console command description.
*
* @var string
*/
protected $description = 'Run migrations from multiple folders in specific sequence ';
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$this->call('migrate', ['--path' => 'database/migrations']);
$this->call('migrate', ['--path' => 'Modules/HRManagement/Database/Migrations']);
$this->call('migrate', ['--path' => 'Modules/FleetService/Database/Migrations']);
$this->call('migrate', ['--path' => 'Modules/BusinessService/Database/Migrations']);
$this->call('migrate', ['--path' => 'Modules/DeliveryService/Database/Migrations']);
$this->call('migrate', ['--path' => 'Modules/FinanceService/Database/Migrations']);
$this->info('Multiple migrations of project ran successfully');
}
}
Inside tinker.php
'commands' => [
app\Console\Commands\RunMultipleMigrations::class
],
migration snapshots
Another thing to note that issue is happening only on live server when I’m using SSH. In local server, above procedure is working fine
Please let me know if I need to share anything else
What I have tried to solved above?
- Caching Issue: Ran php artisan config:clear and php artisan cache:clear.
- Manual Check: Opened your database and see if the table
business_categories
actually exists. But it don’t exist - Ran single migrations
php artisan migrate --path=Modules/BusinessService/Database/Migrations/2023_04_07_065850_create_business_categories_table.php
It ran as intended but from where migrate ommand is detecting2023_04_08_065850_create_business_categories_table
?
UPDATE: Point to ponder
2023_04_08_065850_create_business_categories_table
this migration don’t even exist in the project directory, as I’ve already shared the screenshots. Main point here is that it is happening only on live server, when running from SSH. I have cleared the cache and all but somehow it is keeping track of old migrations. I mean they were in the project before but I removed them afterwards. This thing also happenned when I tried to run migration of FinanceService folder. 2023_08_10_043908_create_wallet_deductions_table
is not in migration folder but migrate command tried to run it. It was also alse present before.
One more thing, can you put feedback on each migration, 2nd thing your migration run twice why ? because you have 2023_04_08_065850_create_business_categories_table and 2023_04_07_065850_create_business_categories_table different
@PsyLogic
2023_04_08_065850_create_business_categories_table
this migration don’t even exist in the project directory, as I’ve already shared the screenshots. Main point here is that it is happening only on live server, when running from SSH. I have cleared the cache and all but somehow it is keeping track of old migrations. I mean they were in the project before but I removed them afterwards. This thing also happenned when I tried to run migration ofFinanceService
folder.2023_08_10_043908_create_wallet_deductions_table
is not in migration folder but migrate command tried to run it.Did you try fresh migration
Yes I removed everything. before running migrations
Ok can you make a migration status on each Module to see what it’s really listing, just to make sure what you have is the same what status will return
Show 1 more comment