Uploaded image for project: 'Doctrine DBAL'
  1. Doctrine DBAL
  2. DBAL-844

[GH-549] Fix truncate on MySQL >= 5.5


    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All
    • Labels:


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

      Url: https://github.com/doctrine/dbal/pull/549


      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](http://dev.mysql.com/doc/refman/5.5/en/truncate-table.html):

      > 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: https://github.com/doctrine/data-fixtures/pull/127. However, as @deeky666 pointed out, the DBAL is a better place for the fix.


        There are no comments yet on this issue.


          • Assignee:
            beberlei Benjamin Eberlei
            doctrinebot Doctrine Bot
          • Votes:
            1 Vote for this issue
            2 Start watching this issue


            • Created: