In many cases where a relationship exists between tables, the columns that define the relationship have different definitions. For example, the uid column in the users table is defined as:

      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Primary Key: Unique user ID.',
        'default' => 0,
      ),

But in the comment table, it is defined as:

      'uid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The {users}.uid who authored the comment. If set to 0, this comment was created by an anonymous user.',
      ),

Notice uid is unsigned in the users table but not in the comment table.

When these columns are created in MySQL, this makes a difference:

CREATE TABLE `users` (
  `uid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Primary Key: Unique user ID.',
  ...
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Stores user data.'

CREATE TABLE `comment` (
  `cid` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key: Unique comment ID.',
  ...
  `uid` int(11) NOT NULL DEFAULT '0' COMMENT 'The users.uid who authored the comment. If set to 0, this comment was created by an anonymous user.',
   ...
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Stores comments and associated data.

uid is int(10) unsigned in the users table but int(11) in the comment table.

If it ever becomes desirable to actually create the foreign keys that are specified in the schema metadata, MySQL will not allow due to these mis-matching column definitions. From the MySQL docs (http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html) - "Corresponding columns in the foreign key and the referenced key must have similar internal data types inside InnoDB so that they can be compared without a type conversion. The size and sign of integer types must be the same."

CommentFileSizeAuthor
#1 drupal-fix-col-defs-1701822-0.patch2.94 KBposulliv
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

posulliv’s picture

Patch attached to make column definitions in core match up.

Liam Morland’s picture

Status: Active » Closed (duplicate)