Doctrine DBAL
  1. Doctrine DBAL
  2. DBAL-844

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

    Details

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

      Description

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

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

      Message:

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

      ```mysql
      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.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Doctrine Bot
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: