Skip to content
Advertisement

Artisan::call(‘migrate’) stuck in column renaming

I got a weird behaviour in my current project i am working on. While all my migrations work fine through the command line using php artisan migrate they don’t run through the Artisan command.

The goal is to spin a new DB and run migrations there so my code for that part looks like:

 DB::statement("CREATE DATABASE TESTDB");


DB::disconnect('mysql');
Config::set('database.connections.mysql.database', 'TESTDB');
DB::connection('mysql')->reconnect();

Artisan::call('migrate',
    [
        '--database' => 'mysql',
        '--path'     => 'database/migrations'
    ]);

The db is created successfully so no issues there and the migrations start to run but always fail in migrations that have to do with renaming a column claiming that column is not there.

Error message

“There is no column with name ‘parent_version_id’ on table

But the column is still there it’s just not renamed.

Renaming migration line:

    $table->renameColumn('parent_version_id', 'child_version_id');

If i remove this line the migration will run (of course won’t rename the column it will just pass through) and will fail in the next renaming migration.

Keep in mind that if i change manually my db in the env file and run migrations they will run smooth without any issues but i want it to be dynamically created and set that’s why i switch DBs on the fly.

Advertisement

Answer

Apparantly the fix was replacing 1 line of code.

Instead of :

DB::connection('mysql')->reconnect();

Used:

DB::purge('mysql');

Which seems to also remove old cache which was conflicting with doctrine.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement