A
A
Alexey Anisimov2017-03-28 10:50:47
symfony
Alexey Anisimov, 2017-03-28 10:50:47

How to clear data in all tables without deleting base and base schema?

Good afternoon.
The project is big. More than 350 queries while executing doctrine:schema:create command (runs for over a minute, and 500 scripts will run for over 500 minutes).
In tests, it is required to recreate fixtures after the script is executed. But if the base is not deleted, then the primary key counter is not reset. Therefore, it will not be possible to request data by id (since it changes after each test).
For example, such a request is GET /api/article/1 (getting an article by id). If the test with this request runs first , then the article with this id exists and the test is successfully executed.
If this query is executed after some other script, then the article with id=1 will no longer be in the database, since when the fixtures are loaded, the tables will be cleared, but the primary key counter will not be there.
Running the command php app/console doctrine:fixtures:load --purge-with-truncate -e=test (with clearing the primary key counter) throws an error due to relationships between entities.
How can I run php app/console doctrine:fixtures:load --purge-with-truncate -e=test command without getting SQLSTATE[42000]: Syntax error or access violation: 1701 Cannot truncate a table referenced in a foreign key constraint ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Anisimov, 2017-03-28
@AnisimovAM

Found a solution here https://coderwall.com/p/staybw/workaround-for-1701...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question