DDC-212: Disable mysql foreign key check for dropping database #2806

Closed
doctrinebot opened this Issue Dec 15, 2009 · 3 comments

2 participants

@doctrinebot

Jira issue originally created by user bmills:

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? 
@doctrinebot

Comment created by @beberlei:

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

@doctrinebot

Comment created by bmills:

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

@doctrinebot

Issue was closed with resolution "Duplicate"

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.0-ALPHA4 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment