Drupal add new field as primary_key and move column via hook_update_N

by Abdul Gaffar Shah   Last Updated November 02, 2017 07:07 AM

I have created hook_update_N to add primary_key to existing table everything works fine and new column is added in table but I need that column to be moved first. see working code:

function MODULENAME_dashboard_update_7115(){ db_add_field('table_name', 'cid', array( 'type' => 'int', 'not null' => TRUE, 'default' => 0, 'weight' => -50, )); db_drop_primary_key('table_name'); db_change_field('table_name', 'cid', 'cid', array( 'type' => 'serial', 'not null' => TRUE, 'unsigned' => TRUE, 'description' => 'Holds the identifier of the column.', 'weight' => -50, ), array('primary key' => array('cid')) );

Tags : updating

Related Questions

Check when core was updated

Updated February 16, 2016 16:03 PM