Symfony2: deleted property still used in query - symfony

I deleted a property (teaser) from an enitiy (sale).
I used the CLi to update the database & entites:
$ php app/console doctrine:schema:update --complete --force
$ php app/console doctrine:generate:entities Our --no-backup
$ php app/console doctrine:cache:clear-metadata
$ php app/console doctrine:cache:clear-result
And i cleared the cache:
$ php app/console cache:clear --no-optional-warmers --no-warmup
Now i have a query created by query builder:
$qb = $this->createQueryBuilder('s');
$q = $qb
->select('s.id')
->leftJoin('s.bills','b')
->where('b.paid = true')
->getQuery()
->getResult();
This throws an error becuas eit generates a select statement that includes the old property:
Column not found: 1054 Unknown column 's0_.teaser' in 'field list'
I tried to understand how Doctrine executes the query but failed to find the source of the problem.
Does anyone have any clues?
UPDATE: I took the DQL from the query, generated by the querybuilder and then used that to create a new Query. Same Error. Then i changed one word in the DQL from uppercae to lowercase (LEFT is now Left) and that one executed just fine.
$q = $this->getEntityManager()
->createQuery('SELECT s,b FROM Our\BuyBundle\Entity\Sale s Left JOIN s.bills b WHERE s.id IN (:randomIds)')
->setParameter('randomIds', $allSaleIds);
So it seems the DQL Statement is cached somewhere, Using the DQL as a hash to get the corresponding SQL Statement.
I still can't quite figure out where and how to clear that cached Information. Especially given the fact that i deleted all content in the app/cache folder as well.
UPDATE2: Found the Solution. Had to clear the APC Cache manually since the console can't do that.
So the Solution would be:
$ php app/console doctrine:cache:clear-query
And if that doesn't work, clear your APC Cache.

My Problem was the APC Cache.
I could not clear the query-cache in CLI (app/console) since the console can't (or is not allowed to) clear the APC Cache.
So i had to clear the APC Cache manually.
Solution is:
$ php app/console doctrine:cache:clear-result
And if that doesn't work, clear the APC Cache (or whatever cache you use) manually.

Related

Previously executed migration are not registered migrations

I'm trying to update my database with those commands
php bin/console make:migration
this return success
But when I try
php bin/console doctrine:migrations:migrate
I have this error:
WARNING! You have 5 previously executed migrations in the database >>that are not registered migrations.
>> 2018-12-17 10:42:04 (20181217104204)
>> 2018-12-17 13:19:24 (20181217131924)
>> 2018-12-17 13:40:58 (20181217134058)
>> 2018-12-18 10:41:38 (20181218104138)
>> 2018-12-18 13:15:49 (20181218131549)
Thing is, the database listed here are not in my migrations table from my database and they are not in my Migrations folder either.
How can I remove those wrong migrations ? Thanks.
This is a year old, but I've had problems a few times where I delete old migration files because they aren't relevant or whatever reason and had the same issue. I think the correct way to handle this is to delete references from the table directly.
php bin/console doctrine:query:sql "delete from migration_versions where version = '2020181217104204'";
EDIT - newer versions of Symfony are now using a "doctrine_migration_versions" table.
php bin/console doctrine:query:sql "delete from doctrine_migration_versions where version = '2020181217104204'";
Etc..
Encounterd the same probleme : I had previously copied already executed migration to the newly created migration table (due to doctrine update).
Renaming all version names as follow saved the day : 20190408092436 --> DoctrineMigrations\Version20190408092436

Translate Validation Constraint Messages on Symfony

In order to have error messages in different languages, I am following the instructions under this link:
https://symfony.com/doc/current/validation/translations.html
I made the validator files with yaml:
For instance:
# translations/validators.en.yml
author.name.not_blank: Please enter the name of the author.
Notice: I tried the extensions yaml and yml
And in src/entity/Data.php
/**
* #var string
*#Assert\NotBlank(message="author.name.not_blank")
*/
private $author;
I just get the message "author.name.not_blank" instead of "Please enter the name of the author."
I cleared the cache like this:
https://symfony.com/doc/2.7/console/usage.html
php app/console cache:clear --env=prod
I get the temporary message on the terminal "Clearing the cache for the prod environment with debug false"
So my questions are: Am I doing something wrong in clearing the cache?
I am using Symfony 2.7
Is there something I am missing ?
By the way, all other translations from files such as
translations/messages.en.yml
are functionning perfectly well.
Thank you very much!
I see your code is fine:
now you can check additional stuff:
app/config:
translator: { fallbacks: ["%locale%"] }
and be sure which environment are you in.
instead of
php app/console cache:clear --env=prod
try
php app/console cache:clear
hope this will helps.

Symfony & Doctrine - Repository or Doctrine cache to clear?

My environment :
Symfony 2.7
Custom Bundle "IpadBundle".
Entity is "Checksum.php" and my controller is "MainController.php".
All work perfect when i Use the findAll() method on my repo. Then
I added 2 new properties in my entity ($file_path and $creation_date)
Getters and Setters were generated by app/console doctrine:generate:entities IpadBundle:Checksum
Mysql database has been updated via doctrine:schema:update --force
I went to my phpmyadmin to fill manually the 2 new cols
... but result of findAll() doesn't include these new cols ! I tried :
cache:clear --env=prod
cache:warmup
"$cacheDriver = new \Doctrine\Common\Cache\ArrayCache();" + "$cacheDriver->deleteAll();"
"app/console doctrine:cache:clear-metadata" + "app/console doctrine:cache:clear-query" + "app/console doctrine:cache:clear-result".
But no results.
Any idea ?
Sometimes that happend to me and the only thing I do is restart apache and whola. Is weird IDK why apache saves some cache for entities, try it and let me know if that works for you. Good Luck !

Symfony2 generate entities error

I'm trying to generate entities from existing tables in database, I keep getting the same error in a particular entity, which is imported from a second database (or entity manager), but I re-created this table in main database to use the same entity manager and get the same error, so I'm lost about what is happening.
This are my commands to generate it:
php app/console doctrine:mapping:convert yml ./src/MyShop/ProductBundle/Resources/config/doctrine/metadata/orm --from-database --filter="Product" --em=mysecondaryem
(BTW, is there a way to force exact filter? I only need Product)
Which seems to be ok:
Processing entity "ProductSold"
Processing entity "Product"
Exporting "yml" mapping information to...
Then
php app/console doctrine:mapping:import MyShopProductBundle annotation --em=mysecondaryem
Which is weird, as it is logging information about all other tables existing in this db but it's only generating the corresponding to "Product" as filtered (only the files ProductSold.php and Product.php do really exist):
Importing mapping information from "mysecondaryem" entity manager
> writing C:\mysite\src\MyShop\ProductBundle/Entity/ProductSold.php
> writing C:\mysite\src\MyShop\ProductBundle/Entity/Family.php
> writing C:\mysite\src\MyShop\ProductBundle/Entity/Category.php
> writing C:\mysite\src\MyShop\ProductBundle/Entity/Item.php
> writing C:\mysite\src\MyShop\ProductBundle/Entity/Stock.php
> writing C:\mysite\src\MyShop\ProductBundle/Entity/Product.php
Then, in the third step, I get an error:
php app/console doctrine:generate:entities MyShopProductBundle --no-backup
Generating entities for bundle "MyShopProductBundle"
[RuntimeException]
Bundle "MyShopProductBundle" does not contain any mapped entities.
doctrine:generate:entities [--path="..."] [--no-backup] name
As I sayed, I tried omitting secondary entity manager (replicating tables in my first database) and I get the same error.
You've verified that C:\mysite\src\MyShop\ProductBundle/Entity/Product.php has been created, but have you also checked that it actually contains mapped entities ?
Ok, I found the error, I was missing --force parameter, first step command should be:
php app/console doctrine:mapping:convert yml ./src/MyShop/ProductBundle/Resources/config/doctrine/metadata/orm --from-database --force --filter="Product" --em=mysecondaryem

Create Entities from existing DB

Newest Version Symfony2 and using MAMP on a MAC. Following command:
php app/console doctrine:mapping:convert yml ./src/Acme/DemoBundle/Resources/config/doctrine/metadata/orm --from-database --force
My Error:
[Doctrine\DBAL\DBALException]
Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it.
Don't have any idea. What is wrong?
A connection to my db is working. Because I tried to create a table and the output was that the table exist.
Sorry, I missed it and here is the solution of my question.
http://symfony.com/doc/current/cookbook/doctrine/dbal.html#registering-custom-mapping-types-in-the-schematool

Resources