[DBAL-232] Custom commented column type removal causes unknown column type exception Created: 06/Mar/12  Updated: 21/Nov/13  Resolved: 21/Nov/13

Status: Resolved
Project: Doctrine DBAL
Component/s: Schema Managers
Affects Version/s: 2.2.1
Fix Version/s: None
Security Level: All

Type: Improvement Priority: Major
Reporter: Aigars Gedroics Assignee: Benjamin Eberlei
Resolution: Won't Fix Votes: 0
Labels: None


Problem happens when initially, as example, there was commented type "foo" registered and used:

Doctrine\DBAL\Types\Type::addType('foo', 'FooType');

When the type usage and declaration is removed, the database schema upgrade fails.
This is because DBAL reads the comment from the database and tries to find the type 'foo'.

I suggest ignoring the database column comment and stick to the standard type recognition in case the type is not declared.

Comment by Aigars Gedroics [ 09/Mar/12 ]

Trivial solution would be:

--- a/Doctrine/DBAL/Schema/AbstractSchemaManager.php
+++ b/Doctrine/DBAL/Schema/AbstractSchemaManager.php
@@ -878,7 +878,9 @@ abstract class AbstractSchemaManager
     public function extractDoctrineTypeFromComment($comment, $currentType)
         if (preg_match("(\(DC2Type:([a-zA-Z0-9]+)\))", $comment, $match)) {
-            $currentType = $match[1];
+                       if (Types\Type::hasType($match[1])) {
+                               $currentType = $match[1];
+                       }
         return $currentType;
Comment by Steve Müller [ 07/Nov/13 ]

Proposed solution applied in PR:


Comment by Doctrine Bot [ 09/Nov/13 ]

A related Github Pull-Request [GH-406] was closed:

Comment by Steve Müller [ 09/Nov/13 ]

As discussed with ocramius, it is not a good solution to silence this error during schema introspection. The problem has to be fixed by registering the missing types in the application or modifying the database schema manually by removing the column comment. This is what the current exception message suggest anyways.

Generated at Tue Oct 06 18:48:38 EDT 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.