-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
artisan migrate with --pretend flag doesn't work with multiple connections #36596
Comments
Hey @dshafik! When controlling the connection within migrations, set the protected $connection = 'testing';
public function up()
{
Schema::create('testing', function (Blueprint $table) {
$table->id();
$table->timestamps();
});
} |
@taylorotwell I tested with |
@dshafik what if you do the $connection property and use the connection() call? That seems to exhibit the correct behavior for me. |
So - digging into the code - it seems the connection property has a couple purposes 1) it informs the migrator what connection the migration will be running on when However, it seems within your migration I somewhat expected the connection property to set the default database connection before the |
Description:
When using the
--pretend
flag withphp artisan migrate
and using multiple connections, the schema changes are actually applied to the non-default DB.Steps To Reproduce:
Add a second DB to
config/database.php
e.g.testing
:Create a fresh migration:
Update the
up()
method to use the new connection:Run migrate with pretend:
When doing this, I see the standard
--pretend
SQL output for migrations using the default DB connection, but this migration runs no matter what (and no--pretend
SQL output), e.g. if you alsophp artisan make:migration create_foo_table
and don't modify it:Additionally the
migrations
table isn't updated (as expected), so If you run it again, it'll fail because thetesting
table already exists, and if you try to rollback, it'll rollback the previous migration, which could be disastrous.The text was updated successfully, but these errors were encountered: