I want to empty a table in my MySQL database. How can I do that with Doctrine?
相关问题
- sqlyog export query result as csv
- NOT DISTINCT query in mySQL
- MySQL: conduct a basic search
- Why sometimes there is one of more gap(s) in the v
- mySQL alter table on update, current timestamp
Truncating a table with Doctrine is as "simple" as:
But you have to know that MySQL will not be able to truncate any table once it has a foreign key constraint.
If you have a problem with foreign key I working with :
You can truncate data in MySQL via Doctrine so that it ignores foreign key constraints...
If you want to remove entities including associated entities that are eventually connected by foreign keys you could use a simply DQL batch query instead of truncating:
http://doctrine-orm.readthedocs.org/en/latest/reference/batch-processing.html#dql-delete
This will only work with associations if you correctly configured cascade operations and orphanRemoval e.g.:
This is not a direct answer regarding the MySQL TRUNCATE command but since it is realted to Doctrine this approach could solve your issue.
I generalized the answer before to a nice function which I have used in my project, feel free to share.
Short variant (most useful in migrations) !