Reputation: 5530
I have .env
and .env.test
files with different APP_ENV
and DATABASE_URL
values.
In .env
I have DATABASE_URL=pgsql://postgres:asdfasdf@db:5432/real_db
and in .env.test
I have DATABASE_URL=pgsql://postgres:asdfasdf@db:5432/test_db
But when I run command bin/console doctrine:database:create --if-not-exists --env=test
I can see message Database "real_db" for connection named default already exists. Skipped
So looks like for some reason Symfony cli can't recognize env correctly.
Also, I having a pretty similar issue when running bin/console doctrine:schema:update --end=dev
. When I run it I see warning message [CAUTION] This operation should not be executed in a production environment! and I need to use --force
to update the schema.
How can I fix this, especially issue with no ability to create testing DB? Thanks!
Upvotes: 0
Views: 996
Reputation: 861
By default .env
file only work on dev
environment. So .env.xxx
not related to any environment, you can't split env
file like that but you need to manually export
environment's variables for each environment. Read more from this link https://symfony.com/doc/current/configuration/environments.html and http://fabien.potencier.org/symfony4-best-practices.html
For testing variables can be defined in phpunit.xml
-- See https://symfony.com/doc/current/testing/database.html#changing-database-settings-for-functional-tests
And for [CAUTION] This operation should not be executed in a production environment!
is a good caution don't worry about it, using --force
can prevent you from some mistake.
Upvotes: 1