Domanda

ho questo schema, che ho bisogno di definire due chiavi primarie; uno è campo 'vid' di Drupal e l'altro è il mio sito campo 'bid', che è di tipo automatico incremento che a sua volta richiede che sia una chiave primaria: wtherwise ottengo MySQL errore. Sto avendo problemi a trovare la sintassi per la definizione più chiavi primarie in uno schema Drupal. Se qualcuno mi può aiutare con la sintassi, ho praticamente apprezzo.

$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;
}
È stato utile?

Soluzione

Utilizzando la seguente ha funzionato bene per me. Forse è una limitazione versione specifica di MySQL? Si può riferire il messaggio di errore effettivo si ha quando Drupal ha cercato di creare questa tabella?

$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'),
);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top