Uploaded image for project: 'Doctrine 1'
  1. Doctrine 1
  2. DC-426

Doctrine incorrectly assigns a NULL value to primary key fields


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



      in my project (MySQL 5.x, PHP 5.2.x), I use a combined primary key which looks as follows:

      $this->hasColumn("guid", "string", 32, array('primary' => true));
      $this->hasColumn("revision", "integer", 4, array('primary' => true));
      $this->hasColumn("language", "string", 32, array('primary' => true));

      My project automatically initializes the GUID and revision fields, but language is left empty. Doctrine assumes that NULL is a good value, and uses the NULL value after saving an object to reload it. This results in the following statement, generated by the find()-Method within Table.php:

      SELECT b.guid AS b_guid, b.revision AS brevision, b.language AS blanguage, b.active AS bactive, b.title AS btitle, b.content AS bcontent, b.category AS b_category FROM blog_entry b WHERE (b.guid = '505f1a2d13864fa4aef461aa1b5b37a3' AND b.revision = '1' AND b.language = NULL)

      Since MySQL does not allow NULL values in primary keys, MySQL uses an empty string (''). Doctrine should also use an empty string as default value if the primary key consists of a string, OR issue a warning that MySQL does not allow NULL values in primary keys. The problem with this "bug" is that problems occur in situations where you do not expect them, for example, when storing objects.

      If a test case is required, just tell me and I'll prepare one.

      Thanks and best regards,


        There are no comments yet on this issue.


          • Assignee:
            jwage Jonathan H. Wage
            alek202 Timo A. Hummel
          • Votes:
            0 Vote for this issue
            0 Start watching this issue


            • Created: