我正在尝试将laravel应用程序部署到heroku。我已经使用我的一个应用程序成功完成了此操作,但是在这里运行命令heroku run php artisan migration时出现以下错误:
In Connection.php line 664:
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from
information_schema.tables where table_schema = todolist and
table_name = migrations)
In Connector.php line 67:
SQLSTATE[HY000] [2002] Connection refused
我已经检查了database.php和.env是否具有匹配的配置:
.env:
DB_CONNECTION=pgsql
DB_HOST=foo.amazonaws.com
DB_PORT=5432
DB_DATABASE=database
DB_USERNAME=user
DB_PASSWORD=password
database.php:
return [
'default' => env('DB_CONNECTION', 'pgsql'),
'connections' => [
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'foo.amazonaws.com'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'database'),
'username' => env('DB_USERNAME', 'user'),
'password' => env('DB_PASSWORD', 'password'),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
]
]
我已经阅读了一些类似的文章,并尝试将DB_HOST从127.0.0.1更改为localhost,但这没有用。
在我将postgres用于数据库后,数据库值由heroku给出。我在这里想念什么吗?欢迎提供所有建议。
答案 0 :(得分:3)
.env文件被git忽略,因此不会被推送到Heroku。要解决您的问题,凭据应该以与您拥有凭据相同的方式存储在database.php文件中:
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'ec2-12-34-56-789.compute-1.amazonaws.com'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'dbXXXXXXXXXXXX'),
'username' => env('DB_USERNAME', 'XXXXXXXXXXXXXX'),
'password' => env('DB_PASSWORD', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
]
密码应为64个字符长,所以我想说可能要仔细检查一下值,然后再次推送更改。成功推送后,运行:
$ heroku run php artisan migrate