Skip to content

Loading…

DBAL-844: [GH-549] Fix truncate on MySQL >= 5.5 #2080

Closed
doctrinebot opened this Issue · 0 comments

3 participants

@doctrinebot

Jira issue originally created by user @doctrinebot:

This issue is created automatically through a Github pull request on behalf of ddeboer:

Url: #549

Message:

When truncating tables on MySQL >= 5.5, an error is thrown:

SQLSTATE[42000]: Syntax error or access violation: 
1701 Cannot truncate a table referenced in a foreign key constraint ...

It turns out that with MySQL 5.5.7, TRUNCATE behaviour has changed. From the MySQL docs:

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.

With this PR foreign key checks are disabled just before and re-enabled just after truncate.

As I encountered this issue using doctrine/data-fixtures, I originally submitted a fix there: doctrine/data-fixtures#127. However, as @deeky666 pointed out, the DBAL is a better place for the fix.

@doctrinebot doctrinebot added the Bug label
@beberlei beberlei was assigned by doctrinebot
@deeky666 deeky666 added Duplicate and removed Bug labels
@beberlei beberlei was unassigned by deeky666
@deeky666 deeky666 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.