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 `Illuminate\Database\Migrations\Migration` $connection property but Do not work #25350

Closed
acodercat opened this Issue Aug 27, 2018 · 9 comments

Comments

Projects
None yet
4 participants
@acodercat
Copy link

acodercat commented Aug 27, 2018

  • Laravel Version: 5.5
  • PHP Version:7.1
  • Database Driver & Version: mysql5.7

Description:

Migration overwrite Illuminate\Database\Migrations\Migration $connection property but Do not work,migrated to the default database.

Steps To Reproduce:

php artisan migrate

@staudenmeir

This comment has been minimized.

Copy link
Contributor

staudenmeir commented Aug 27, 2018

Please post your migration.

@acodercat

This comment has been minimized.

Copy link
Author

acodercat commented Aug 27, 2018

<?php

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

class CreateDiseaseTable extends Migration
{

    protected $connection = 'PhysicalExamItem';
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('disease', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name', 32)->default('')->comment('疾病名称');
            $table->integer('type_id')->comment('疾病类别id');
            $table->text('intro')->default('')->comment('简介');
            $table->text('cause_or_hazard_factor')->default('')->comment('病因或危害因素');
            $table->text('clinical_manifestation')->default('')->comment('临床表现');
            $table->text('advice')->default('')->comment('建议');
            $table->text('remark')->default('')->comment('备注');
            $table->text('prognosis')->default('')->comment('预后');
            $table->boolean('is_enable')->default(true)->comment('是否启用');
            $table->string('operator', 32)->comment('最后修改人');
            $table->integer('display_order')->default(0)->comment('显示顺序');
            $table->timestamps();
            $table->softDeletes();
        });
    }

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

This comment has been minimized.

Copy link
Author

acodercat commented Aug 27, 2018

in databases config

    'PhysicalExamItem' => [
            'driver' => 'pgsql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_DATABASE', 'peis_user'),
            'username' => env('DB_USERNAME', 'codercat'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'schema' => 'oauth',
            'sslmode' => 'prefer',
        ],
@acodercat

This comment has been minimized.

Copy link
Author

acodercat commented Aug 27, 2018

I hope migrate to PhysicalExamItem

@acodercat

This comment has been minimized.

Copy link
Author

acodercat commented Aug 27, 2018

I don't want to use Schema::connection('PhysicalExamItem')

@staudenmeir

This comment has been minimized.

Copy link
Contributor

staudenmeir commented Aug 27, 2018

Judging from the description of $connection, this should work.

But after looking at the implementation, I'm not sure this is possible to fix. AFAICS, Schema::create() doesn't know which connection its migration uses.

@X-Coder264

This comment has been minimized.

Copy link
Contributor

X-Coder264 commented Aug 27, 2018

@acodercat You can change the schema connection by using $schema = Schema::connection('PhysicalExamItem'); and then $schema->create() like usual.

Ah sorry, I just saw that you don't wanna use that. Why not?

@laurencei

This comment has been minimized.

Copy link
Member

laurencei commented Sep 18, 2018

I don't want to use Schema::connection('PhysicalExamItem')

I'm not sure what else can be done. If you dont want to use the support functions there's not much else we can do?

@laurencei laurencei closed this Sep 18, 2018

@acodercat

This comment has been minimized.

Copy link
Author

acodercat commented Sep 18, 2018

@laurencei I want overwrite Illuminate\Database\Migrations\Migration $connection property

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment