Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-212

Disable mysql foreign key check for dropping database

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 2.0-ALPHA3
    • Fix Version/s: 2.0-ALPHA4
    • Component/s: Tools
    • Security Level: All
    • Labels:
      None
    • Environment:
      os x 10.5, mysql 5.1.35, php 5.3.0

      Description

      When creating schema via the CLI, it automatically adds foreign keys for associated rows:

      CREATE TABLE images (id INT AUTO_INCREMENT NOT NULL, description VARCHAR(255) NOT NULL, filename VARCHAR(255) NOT NULL, path VARCHAR(255) NOT NULL, type INT NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, photographer_id INT DEFAULT NULL, PRIMARY KEY(id)) ENGINE = InnoDB
      CREATE TABLE photographers (id INT AUTO_INCREMENT NOT NULL, fname VARCHAR(255) NOT NULL, mname VARCHAR(255) NOT NULL, lname VARCHAR(255) NOT NULL, slug VARCHAR(255) NOT NULL, image_path VARCHAR(255) NOT NULL, active TINYINT(1) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, headshot_id INT DEFAULT NULL, PRIMARY KEY(id)) ENGINE = InnoDB
      ALTER TABLE images ADD FOREIGN KEY (photographer_id) REFERENCES photographers(id)
      ALTER TABLE photographers ADD FOREIGN KEY (headshot_id) REFERENCES images(id)
      

      When I also use the CLI to drop the entire database schema, it fails the foreign key check:

       $ ./doctrine schema-tool --drop=database 
       Dropping database schema...
      SchemaTool: exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1217 Cannot delete or update a parent row: a foreign key constraint fails' in /Users/WM_imac/Sites/library/Doctrine/DBAL/Connection.php:589
      

      If the SchemaTool is responsible for creating foreign keys, should it not also be responsible for removing them when dropping the entire database?

        Activity

        Hide
        Benjamin Eberlei added a comment -

        Is this on the ALPHA 3 release and not trunk? If yes this is fixed already.

        Show
        Benjamin Eberlei added a comment - Is this on the ALPHA 3 release and not trunk? If yes this is fixed already.
        Hide
        Bryan Mills added a comment -

        This was in ALPHA-3. Thanks for the fix!

        Show
        Bryan Mills added a comment - This was in ALPHA-3. Thanks for the fix!

          People

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

            Dates

            • Created:
              Updated:
              Resolved: