I had a table "user" and later i renamed this to "Users", but while generating entities with doctrine: generate entities command, the deleted table always appears. Surprisingly, the same table is not appearing among in doctrine orm.xml files list.
I had removed all orm.xml files, entities files, cleared cache and tried again, but still the same error appears.
It will be really helpful if someone can guide me since im a beginner in doctrine.
Thanks and regards,
Tismon Varghese
Related
Very simple question I'm not able to find a good answer for...
I have a lot of Entities in my Symfony 2.6 - when ever a user makes some changes to any one of them I would like to have a log entry with who/what/where.
Who maked the changes. (user id)
What did he/she do. ( POST/PUT data)
Where was this done (which entity / url)
[EDIT]
It could perhaps just be a table with these columns:
userid
data
entity
created
[/EDIT]
Is there a bundle for this?
For my projects I usually use the EntityAudit bundle. What it does is save a copy of the old state whenever an audited entity is changed. By comparing those to the current version you can see what has changed.
It also gives you a revision history that lists all the entities that have changed in your database.
You have several Bundles out there that do this, a couple of which have already been mentioned. I've had a lot of success with Gedmo Doctrine Extensions.
Some Documentation here: http://symfony.com/doc/current/cookbook/doctrine/common_extensions.html
And installation instructions here:
https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/symfony2.md
The installation is the tough part. Once that's done, all you need to do is annotate any entity fields you wish to log.
I do generate entities from database. Here is a file that I generated before updating to new version of doctrine and with the latest version of doctrine:
http://pastebin.com/g8DsUjmm
You will see, it adds an extra 'ORM' in annotations on new ones.
I am now having problem(Exception) while executing doctrine code which says:
Class GdCities does not exist and could not be loaded /my_path/application/third_party/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php
Anyone have any idea, why this is happening. before updating, with old entities and doctrine version, it was working fine.
I did get this resolved by removing the "ORM\" part from all entities' table and column name. Not sure, if its a doctrine bug or I am doing something in different way.
I'm new to migrations, and I'm trying to stick to the automatically generated ones:
$ php app/console doctrine:migrations:diff
$ php app/console doctrine:migrations:migrate
The problem is that this drops my sessions table. What can I do to avoid that?
Another option is simply to tell Doctrine to ignore the table. You can use the schema_filter option as described in this SO post.
So, if your table is called sessions, add the following to config.yml (Symfony < 4) or doctrine.yaml (Symfony >=4 ):
doctrine:
dbal:
# standard database config here
schema_filter: ~^(?!sessions)~
We had a large number of tables to ignore, so we took the opposite approach - we told Doctrine to only consider tables which began with a certain prefix, and set up listeners to ensure all our Doctrine-managed tables had a prefix. The use of listeners for table prefixes is documented at http://docs.doctrine-project.org/en/latest/cookbook/sql-table-prefixes.html and there's a SO post about the Symfony side of it here.
I know I am late to this question, but figured i would offer a suggestion.
import the session tables into your entities. even if you don't use it through the interfaces it creates, it will allow Doctrine to keep track of the tables, so that it knows they are ment to be there.
see:
http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html
When you say "sessions table" I guess you're meaning the sessions table for PdoSessionStorage? (just to be sure we're talking about the same thing :-) )
I had a similar issue, and the only persistent (and non-complex) solution was simply to put your sessions in another database (and update the configuration accordingly). But this requires the permission to create an additional DB.
If you don't have this possibility, I'll look in to some other solution, but maybe the above mentioned one works for you :-)
So heres the scenario:
Currently we have a development site with 3 models. We found we didn't like our initial schema and added a few rows. We re-generated the schema (doctrine:build-sql).
Now it forced us to drop and re-create all the tables and dump back in all the information as no ALTERS were created but rather CREATE statements only. Not a problem...
The big problem came to updating the models. After we ran a build-all and such a few errors popped up i.e. "Widget sort not found" etc. We figured out we needed to rebuild the models. So we can a symfony doctrine:build-models course Course (Course was the table name...course the models). This worked great and fixed the broken links within Symfony.
The downside is all custom code in the actions.class.php file was lost as were customizations to the _form.php page.
My question on this is, how do we store our own actions so they are not lost if you update a models schema? Similarly templates and such are re-generated to but do not hold any customizations.
There surely must be a simple solution to updating a model's schema in symfony?
Found my answer to this. You don't update the module per say but the models of the database. You can change your schema.yml file and do a symfony migration
http://www.slideshare.net/denderello/symfony-live-2010-using-doctrine-migrations
If you just want CRUD/minimal customisation, you can do this with the admin generator:
./symfony doctrine:generate-admin appname Course
A regular module can't be updated once generated without losing customisations - they are intended to be a starting point.
I have Doctrine setup in my Zend Framework application and I built my schema YAML file. But when I tell Doctrine to build the tables it says it does but it doesn't actually make them. It creates the models, and will create the DB but it will not populate the DB with the tables and throws no errors. Does anyone have a guess or know why this is not working?
Thank you.
The issue was that I had a model I created for testing already in the folder. Evidentially Doctrine thought that was a bad idea and then didn't make the tables in the DB.