Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--purge-with-truncate option fails #26

Closed
Gawel1 opened this issue Jan 22, 2014 · 5 comments
Closed

--purge-with-truncate option fails #26

Gawel1 opened this issue Jan 22, 2014 · 5 comments

Comments

@Gawel1
Copy link

Gawel1 commented Jan 22, 2014

When i try to purge data with purge-with-truncate option before insert fixtures, i have a SQL error :

[Doctrine\DBAL\DBALException]                                                                                                                                                                                                             
  An exception occurred while executing 'TRUNCATE table':                                                                                                                                                                      

  SQLSTATE[42000]: Syntax error or access violation: 1701 Cannot truncate a table referenced in a foreign key constraint (`database`.`table`, CONSTRAINT `FK_E75F52F596D36FD` FOREIGN KEY (`foreign_key`) REFE  
  RENCES `database`.`table2` (`id`))                  
@Ocramius
Copy link
Collaborator

This is pretty much normal if you didn't correctly setup cascade operations.

@Gawel1
Copy link
Author

Gawel1 commented Jan 22, 2014

Are you sure? My DB is mysql 5.5 and it appears it can't truncate tables with foreign keys...
I made a cascade "all" in my entity for my relation and the error still exist.

This is the mySQL documentation : TRUNCATE TABLE fails for an InnoDB table if there are any FOREIGN KEY constraints from other tables that reference the table. Foreign key constraints between columns of the same table are permitted.

@Ocramius
Copy link
Collaborator

Did you also set onDelete? Seems also like a MySQL bug to me, why the heck would they implement it like that?

@Gawel1
Copy link
Author

Gawel1 commented Jan 22, 2014

Yes, i tried to add onDelete="CASCADE" on my entity property and i had the same issue.
It appears this is a new security since mysql 5.5 which can be disabled with the following workaround :

SET FOREIGN_KEY_CHECKS=0; TRUNCATE table1; SET FOREIGN_KEY_CHECKS=1;

Do you think that could be used?

@Ocramius
Copy link
Collaborator

@Gawel1 that is a quite bad idea and can lead to FK constraint inconsistencies.

I'll redirect you to doctrine/data-fixtures#17, since the module here simply pushes the flags one level down to data-fixtures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants