Laravel/Vue.js 应用程序和 Heroku 上的 MongoDB 的部署错误

Deployment error with Laravel/Vue.js app and MongoDB on Heroku

我正在尝试在 Heroku 上部署我的 Laravel/Vue.js 应用程序,但在尝试推送时出现错误。

这是错误信息:


       > Illuminate\Foundation\ComposerScripts::postAutoloadDump

       > @php artisan package:discover --ansi


       In DatabaseManager.php line 152:
                           

         Database connection [mysql] not configured.  


       Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

 !     WARNING: A post-autoload-dump script terminated with an error

 !     ERROR: Dependency installation failed!

 !     

 !     The 'composer install' process failed with an error. The cause

 !     may be the download or installation of packages, or a pre- or

 !     post-install hook (e.g. a 'post-install-cmd' item in 'scripts')

 !     in your 'composer.json'.

 !     

 !     Typical error cases are out-of-date or missing parts of code,

 !     timeouts when making external connections, or memory limits.

 !     

 !     Check the above error output closely to determine the cause of

 !     the problem, ensure the code you're pushing is functioning

 !     properly, and that all local changes are committed correctly.

 !     

 !     For more information on builds for PHP on Heroku, refer to

 !     https://devcenter.heroku.com/articles/php-support

 !     

 !     REMINDER: the following warnings were emitted during the build;

 !     check the details above, as they may be related to this error:

 !     - A post-autoload-dump script terminated with an error

 !     Push rejected, failed to compile PHP app.

 !     Push failed

我正在使用 MongoDB,我已经配置了 config/database.php.env

config/database.php :

'default' => env('DB_CONNECTION', 'mongodb'),
[...]
'connections' => [

        'mongodb' => [
            'driver'   => 'mongodb',
            'host' => env('MONGO_DB_HOST', '127.0.0.1'),
            'port' => env('MONGO_DB_PORT', '27017'),
            'username' => env('MONGO_DB_USERNAME', 'username'),
            'password' => env('MONGO_DB_PASSWORD', 'pwd'),
            'database' => env('MONGO_DB_DATABASE', 'name'),
            'options' => [
                'database' => 'admin'
            ],
            'dsn' => env('BD_DNS', 'dns')
        ],

    ],

.env :

DB_CONNECTION=mongodb
DB_DNS=dns
MONGO_DB_HOST=127.0.0.1
MONGO_DB_PORT=27017
MONGO_DB_DATABASE=name
MONGO_DB_USERNAME=username
MONGO_DB_PASSWORD=pwd

我正在使用 jenssegers/mongodb 并在我的 composer.json 中添加了 "ext-mongodb": "*" :

{
   "name": "laravel/laravel",
   "type": "project",
   "description": "The Laravel Framework.",
   "keywords": [
       "framework",
       "laravel"
   ],
   "license": "MIT",
   "require": {
       "php": "^7.2.5",
       "fideloper/proxy": "^4.2",
       "fruitcake/laravel-cors": "^1.0",
       "guzzlehttp/guzzle": "^6.3",
       "jenssegers/mongodb": "3.7.x",
       "laravel/framework": "^7.0",
       "laravel/tinker": "^2.0",
       "laravel/ui": "2.4",
       "tymon/jwt-auth": "^1.0",
       "ext-mongodb": "*"
   },
   "require-dev": {
       "facade/ignition": "^2.0",
       "fzaninotto/faker": "^1.9.1",
       "mockery/mockery": "^1.3.1",
       "nunomaduro/collision": "^4.1",
       "phpunit/phpunit": "^8.5"
   },
   "config": {
       "optimize-autoloader": true,
       "preferred-install": "dist",
       "sort-packages": true
   },
   "extra": {
       "laravel": {
           "dont-discover": []
       }
   },
   "autoload": {
       "psr-4": {
           "App\": "app/"
       },
       "classmap": [
           "database/seeds",
           "database/factories"
       ]
   },
   "autoload-dev": {
       "psr-4": {
           "Tests\": "tests/"
       }
   },
   "minimum-stability": "dev",
   "prefer-stable": true,
   "scripts": {
       "post-root-package-install": [
           "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
       ],
       "post-autoload-dump": [
           "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
           "@php artisan package:discover --ansi"
       ],
       "post-create-project-cmd": [
           "@php artisan key:generate --ansi"
       ]
   }
}

最后,这是我的 Procfileweb: $(composer config bin-dir)/heroku-php-nginx -C nginx.conf public/

我有 运行 php artisan config:cache 再尝试推送之前,但我遇到了同样的错误。 谁能帮我解决这个问题?为什么我的 MongoDB 连接配置不正确?

提前致谢!

问题已解决:我的一个文件中仍有一个 mysql 调用:在我的 config/queue.php 文件

的末尾

我已经改变了这个:

[...] 
    'failed' => [
            'driver' => env('QUEUE_FAILED_DRIVER', 'database'),
            'database' => env('DB_CONNECTION', 'mysql'),
            'table' => 'failed_jobs',
        ],
];

对此:

[...]    
'failed' => [
            'driver' => env('QUEUE_FAILED_DRIVER', 'database'),
            'database' => env('DB_CONNECTION', 'mongodb'),
            'table' => 'failed_jobs',
        ],
];