Adicionar campo a un esquema Drupal 7


//consecutivo
function modulonombre_update_7228() {
    $schema = array(
    'type' => 'int',
    'description' => "id_empresa",
    'not null' => FALSE,
    'default' => 0,
   );   
    db_add_field('formatos', 'id_empresa', $schema);
}

Ejemplo 2
1. Crear tabla
2. En caso de adicionar campo

Paso 1:
 //Create tables empresas No. Paso No. 1
    $schema['empresas'] = array(
        'description' => 'Table empresas .',
        'fields' => array(
            'fmid' => array(
                'description' => 'The primary identifier for empresas.',
                'type' => 'serial',
                'unsigned' => TRUE,
                'not null' => TRUE,
            ),
            'description' => array(
                'description' => 'Description of the form.',
                'type' => 'varchar',
                'length' => 255,
                'not null' => TRUE,
                'default' =>'',
            ),
            'file' => array(
                'description' => 'File.',
                'type' => 'int',
                'not null' => FALSE,
            ),
            'title' => array(
                'description' => 'The title of this empresa.',
                'type' => 'varchar',
                'length' => 255,
                'not null' => TRUE,
                'default' => '',
            ),
            'uid' => array(
                'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.',
                'type' => 'int',
                'not null' => TRUE,
                'default' => 0,
            ),
            'status' => array(
                'description' => 'Boolean indicating whether the empresa is published (visible to non-administrators).',
                'type' => 'int',
                'not null' => TRUE,
                'default' => 1,
            ),
            'created' => array(
                'description' => 'The Unix timestamp when the mass media was created.',
                'type' => 'int',
                'not null' => TRUE,
                'default' => 0,
            ),
            'weight' => array(
                'description' => 'The weight of the empresa.',
                'type' => 'int',
                'not null' => TRUE,
                'default' => 0,
            ),
        ),
        'indexes' => array(
          'empresas_created'  => array('created'),
          'uid'               => array('uid'),
        ),
        'primary key' => array('fmid'),
    );
    return $schema;
}
Paso 2: 

function incauca_update_7226() {

  $schema['empresas'] = array(
        'description' => 'Table empresas .',
        'fields' => array(
            'fmid' => array(
                'description' => 'The primary identifier for empresas.',
                'type' => 'serial',
                'unsigned' => TRUE,
                'not null' => TRUE,
            ),
            'description' => array(
                'description' => 'Description of the form.',
                'type' => 'varchar',
                'length' => 255,
                'not null' => TRUE,
                'default' =>'',
            ),
            'file' => array(
                'description' => 'File.',
                'type' => 'int',
                'not null' => FALSE,
            ),
            'title' => array(
                'description' => 'The title of this empresa.',
                'type' => 'varchar',
                'length' => 255,
                'not null' => TRUE,
                'default' => '',
            ),
            'uid' => array(
                'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.',
                'type' => 'int',
                'not null' => TRUE,
                'default' => 0,
            ),
           
            'status' => array(
                'description' => 'Boolean indicating whether the empresa is published (visible to non-administrators).',
                'type' => 'int',
                'not null' => TRUE,
                'default' => 1,
            ),
            'created' => array(
                'description' => 'The Unix timestamp when the mass media was created.',
                'type' => 'int',
                'not null' => TRUE,
                'default' => 0,
            ),
            'weight' => array(
                'description' => 'The weight of the empresa.',
                'type' => 'int',
                'not null' => TRUE,
                'default' => 0,
            ),
        ),
        'indexes' => array(
          'empresas_created'  => array('created'),
          'uid'               => array('uid'),
        ),
        'primary key' => array('fmid'),
    );
  db_create_table('empresas', $schema['empresas']);
}

Comentarios

Entradas populares