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

Closed
opened 2026-01-22 12:32:42 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Dec 15, 2009).

Originally assigned to: @beberlei on GitHub.

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

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?

Originally created by @doctrinebot on GitHub (Dec 15, 2009). Originally assigned to: @beberlei on GitHub. 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? ```
admin added the Improvement label 2026-01-22 12:32:42 +01:00
admin closed this issue 2026-01-22 12:32:43 +01:00
Author
Owner

@doctrinebot commented on GitHub (Dec 19, 2009):

Comment created by @beberlei:

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

@doctrinebot commented on GitHub (Dec 19, 2009): Comment created by @beberlei: Is this on the ALPHA 3 release and not trunk? If yes this is fixed already.
Author
Owner

@doctrinebot commented on GitHub (Dec 19, 2009):

Comment created by bmills:

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

@doctrinebot commented on GitHub (Dec 19, 2009): Comment created by bmills: This was in ALPHA-3. Thanks for the fix!
Author
Owner

@doctrinebot commented on GitHub (Dec 20, 2009):

Issue was closed with resolution "Duplicate"

@doctrinebot commented on GitHub (Dec 20, 2009): Issue was closed with resolution "Duplicate"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#266