Schema:update for test environnement - symfony

With Symfony 4.2 and Doctrine, I have two .env files :
.env
DATABASE_URL=mysql://me:password#127.0.0.1:3306/base
.env.test
DATABASE_URL=mysql://me:password#127.0.0.1:3306/base_test
If I do the php bin/console doctrine:schema:update --force command : base is updated. ✓
If I do the php bin/console doctrine:schema:update --force --env=test command : base_test is not updated. ✘ I have this message in my console :
[OK] Nothing to update - your database is already in sync with the current entity metadata.

As from the official documentation you should place APP_ENV=test in the .env.test file and run command like so
APP_ENV=test php bin/console command_name

Related

Test and Dev Enviroment on same machine in Symfony Flex / Symfony 4

Can I put my databse configuration in a configuration file in config/packages/test/ somehow?
I want to run my tests on my development PC and do the dev work in parallel.
In Symfony 3 I had 2 configurations files
config_test.yaml and config_dev.yaml
where I could put in 2 different database connections.
Now the database connection is in the .env File, so I can not have 2 of them.
I also need to run my fixtures and database helpers and the 2 databases (dev and test) seperatly:
php bin/console doctrine:schema:update --force --env=dev
php bin/console doctrine:fixtures:load --no-interaction --env=dev
the solution was to remove the databse connection from the .env file and move it into seperated config files again:
config/packages/dev/doctrine.yaml:
parameters:
DATABASE_URL: 'mysql://root#localhost:3306/database'
and
config/packages/test/doctrine.yaml:
parameters:
DATABASE_URL: 'mysql://root#localhost:3306/database_test'
and inthe main doctrine configuration file config/packages/doctrine.yaml:
doctrine:
dbal:
url: '%DATABASE_URL%'
also in phpunit.xml.dist:
<env name="DATABASE_URL" value="mysql://root#localhost:3306/database_test" />
Now you can have your test and dev environment on the same system and your databse is not polluted by testing data and you can update your databases with:
php bin/console doctrine:schema:update --force --env=dev
php bin/console doctrine:schema:update --force --env=test

Issue executing doctrine schema update

I tried to update my database with the command:
php app/console doctrine:schema:update --force
but I got the error:
"No Metadata classes to process"
I had a similar problem and took me a while until I find out how to clear out the cache: Try this:
php app/console cache:clear --env=prod

Unable to execute "doctrine:fixtures:load"

I am running Symfony 2.8.7 on my local machine. I installed Data Fixtures using composer and I am not able to execute following command:
php app/console doctrine:fixtures:load
It tells me there are no commands defined in the "doctrine:fixtures" namespace. What am I doing wrong?

Name conflict in Doctrine after changing database name

Since I changed my main database name in Symfony, I cannot get things to work
as some part of Doctrine (I still haven't found out which) is still stuck with
the old name despite all my updates.
Here are the updates I tried :
Using php bin/console doctrine:database:drop --force followed by
php bin/console doctrine:database:create to try to "restart from scratch"
Destroying app/config/parameters.yml.dist and putting the new database
name in app/config/parameters.yml
Invoking php bin/console cache:clear and php bin/console doctrine:cache:clear-metadata and php bin/console doctrine:cache:clear-query and app/console doctrine:cache:clear-result
What did I forget to update ?
UPDATE : the current answer suggests using php bin/console doctrine:schema:create but does not specify when I should do it. A "restart from scratch" procedure would go something like this :
1. php bin/console doctrine:database:drop --force
2. php bin/console doctrine:database:create
3. php bin/console doctrine:generate:entities MyBundle:MyEntity
4. php bin/console doctrine:schema:update --force
5. php bin/console doctrine:schema:validate
Where should I insert php bin/console doctrine:schema:create in this
sequence ?
Create schema using doctrine:schema:create Check for any errors occuring. You need to establish if there is a configuration error or just sync issue
EDIT:
If you have already code with entites you dont need to run step 3,
just create schema instead. Use phpmyadmin to see what is happening on the database side to establis if database/tables are created. As long as you have correct settings on the both sides eg. user set in databse with create db privillages and same user in config file symfony side all should work correctly.

'The parameter "debug.error_handler.throw_at" must be defined' error after updating to Symfony 2.6

After updating Symfony with Composer to version 2.6 it gives this error:
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException] The parameter "debug.error_handler.throw_at" must be defined.
manualy clear application cache -
remove all files in /app/cache:
rm -r app/cache/*
and then warmup cache for needed environment like that:
app/console cache:warmup --env=prod

Resources