从MySQL迁移到PostgreSQL之后,我一直在将Laravel 5.1与Travis-CI集成时出现问题。我尝试过以下配置:
.env.travis
APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_DATABASE=CDJ_BD
DB_USERNAME=postgres
DB_PASSWORD=
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
.travis.yml
language: php
php:
- 7.0
addons:
postgresql: "9.4"
before_install:
- composer self-update
- cp .env.travis .env
- psql -c 'create database CDJ_BD;' -U postgres
install:
- composer require phpunit/phpunit:4.8.* satooshi/php-coveralls:dev-master
- composer install --dev
script:
- php artisan migrate --seed
- ./vendor/bin/phpunit --coverage-clover ./tests/logs/clover.xml
after_script:
- php vendor/bin/coveralls -v
database.php中
...
'default' => env('DB_CONNECTION', 'pgsql'),
'connections' => [
'testing' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'CDJ_BD'),
'username' => env('DB_USERNAME', 'postgres'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'CDJ_BD'),
'username' => env('DB_USERNAME', 'postgres'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
],
...
运行php artisan migrate --seed
后,抛出以下异常:
[PDOException]
SQLSTATE[08006] [7] FATAL: database "CDJ_BD" does not exist
我的MySQL配置非常相似,运行没有任何问题。有关如何解决此问题的任何建议吗?
感谢。
答案 0 :(得分:2)
正如wildplasser的评论中所建议的,问题是database.php和.travis文件中env('DB_DATABASE', 'CDJ_BD'),
中的CAPS数据库名称。将它们全部切换为小写'cdj_bd'
解决了这个问题。