Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration overwrite $connection property don't work #31060

Closed
4m1n0s opened this issue Jan 7, 2020 · 6 comments
Closed

Migration overwrite $connection property don't work #31060

4m1n0s opened this issue Jan 7, 2020 · 6 comments

Comments

@4m1n0s
Copy link
Contributor

4m1n0s commented Jan 7, 2020

  • Laravel Version: 6.10.0
  • PHP Version: 7.2.18
  • Database Driver & Version: Mysql - 5.7

Description:

I overwrite $connection property in migration, but still migrate on the default database connection

as its described on the "abstract class Migration"

abstract class Migration
{
    /**
     * The name of the database connection to use.
     *
     * @var string|null
     */
    protected $connection;

The migration file i used

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateProjectsTable extends Migration
{
    protected $connection = 'pgsql';
    
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('projects', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('projects');
    }
}

Note: the default connection i use on .env is mysql

@crynobone
Copy link
Member

If the connection name is hardcoded you can use:

Schema::connection('pgsql')->table(...)

@driesvints
Copy link
Member

Please see the answer above.

@4m1n0s
Copy link
Contributor Author

4m1n0s commented Jan 9, 2020

Yes i know this is a solution, but by the concept presented in the $connection property comment is not working...

    /**
     * The name of the database connection to use.
     *
     * @var string|null
     */
    protected $connection;

@iraklisg
Copy link

Indeed the $connection property does not work in Laravel Framework 8.46.0.

The Schema::connection('...') works as expected

@iAmine Is there a way to make $connection property work?

@4m1n0s
Copy link
Contributor Author

4m1n0s commented Jul 14, 2021

@iraklisg Yes, you can check the pull request i have made.

extend the Migrator class and make the needed changes.

@JohnnyWalkerDigital
Copy link
Contributor

JohnnyWalkerDigital commented Sep 12, 2021

I am also having this issue. The documentation states this is the way to set your migration connection. Laravel v8.60.0 (PHP v7.4.11)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants