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

Nova migrations ignore the --database flag #2952

Closed
aaronahearne opened this issue Oct 9, 2020 · 6 comments
Closed

Nova migrations ignore the --database flag #2952

aaronahearne opened this issue Oct 9, 2020 · 6 comments
Labels
needs more info More information is required

Comments

@aaronahearne
Copy link

aaronahearne commented Oct 9, 2020

  • Laravel Version: 7.28.3
  • Nova Version: 3.11.1
  • PHP Version: 7.4.5
  • Database Driver & Version: mysql
  • Operating System and Version: Ubuntu 20.04
  • Browser type and version: Chrome

Description:

Unable to migrate test database due to Nova migrations ignoring --database tag.

Detailed steps to reproduce the issue on a fresh Nova installation:

  1. Using a standard set up of Laravel Nova with a mySql database, run your migrations once and ensure that Nova has also run it's migrations along side. If it has you should see "oauth_*" tables in your database.
  2. Set up a new database connection in your config/database.php file and ensure you have set the relevant variables for your test database in your .env file

// config/database.php

        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],
        'mysql-test' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE_TEST', 'mysql-test'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET_TEST', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

// env.testing

DB_USERNAME=homestead
DB_PASSWORD=secret
  1. Attempt to run migrations against your test database:

php artisan migrate --database=mysql-test

  1. See that your first few migrations work, but when Nova migrations start they have ignored the database flag. Receive the following error:

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'oauth_auth_codes' already exists (SQL: create tableoauth_auth_codes (idvarchar(100) not null,user_idbigint unsigned not null,client_idbigint unsigned not null,scopestext null,revokedtinyint(1) not null,expires_at datetime null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

@crynobone
Copy link
Member

Laravel Nova only use the default Laravel migrations command and it doesn't have anything related to database connection.

@aaronahearne
Copy link
Author

Im sorry @crynobone I don't understand what you mean. Are you saying there is now way to pass the variables to it?

@crynobone
Copy link
Member

@aaronahearne I'm saying that it shouldn't cause this issue as Laravel Nova only uses the default migration command as if any other Laravel packages.

Screenshot 2020-10-12 at 6 29 51 PM

DB_CONNECTION=mysql

Run artisan command with php artisan migrate --database=sqlite

@aaronahearne
Copy link
Author

@crynobone Im sorry I dont understand how that makes any difference, Im not running an sqlite database.

The nova migrations ARE getting triggered without the variables being past to them when I run the migrate command on my own migrations. I have found it documented elsewhere on Laracasts since I've posted this question but also with no answer.

@crynobone
Copy link
Member

The nova migrations ARE getting triggered without the variables being past to them when I run the migrate command on my own migrations.

Please provide reproducing code to prove this, can't reproduce the issue.

@crynobone crynobone added the needs more info More information is required label Oct 13, 2020
@crynobone
Copy link
Member

This actually a bug with Laravel Passport, let's continue the discussion there.

laravel/passport#1370

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info More information is required
Projects
None yet
Development

No branches or pull requests

2 participants