문제

I have this schema which I need to define two primary keys; one is Drupal's 'vid' field and the other one is my site 'bid' field which is of auto increment type which in turn requires it to be a primary key: wtherwise I get MySQL error. I'm having trouble finding syntax for defining multiple primary keys in a Drupal schema. If anyone can help me out with the syntax, I pretty much appreciate it.

$schema['rft'] = array(
    'fields' => array(
        'vid' => array(
            'type' => 'int',
            'unsigned' => TRUE,
            'not null' => TRUE,
            'default' => 0,
        ),
        'nid' => array(
            'type' => 'int',
            'unsigned' => TRUE,
            'not null' => TRUE,
            'default' => 0,
        ),
        'bid' => array(
            'type' => 'serial',
            'size' => 'medium',
            'not null' => TRUE,                         
        ),

    ),
    'indexes' => array(
        'nid' => array('nid'),
    ),
    'primary key' => array('vid'),  //array('vid','bid') doesn't work
);

return $schema;
}
도움이 되었습니까?

해결책

Using the following worked just fine for me. Maybe it's a MySQL version-specific limitation? Can you report back the actual error message you got when Drupal tried to create this table?

$schema['rft'] = array(
    'fields' => array(
        'vid' => array(
            'type' => 'int',
            'unsigned' => TRUE,
            'not null' => TRUE,
            'default' => 0,
        ),
        'nid' => array(
            'type' => 'int',
            'unsigned' => TRUE,
            'not null' => TRUE,
            'default' => 0,
        ),
        'bid' => array(
            'type' => 'serial',
            'size' => 'medium',
            'not null' => TRUE,                         
        ),

    ),
    'indexes' => array(
        'nid' => array('nid'),
    ),
    'primary key' => array('vid', 'bid'),
);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top