I need to rename one of my fields in a table via a .install file. How can I to do this ?

Let us consider I have a table called "register" and field name called "fname". Now I need to change the field name "fname" to "name". How can I do this using a .install file?

We can add a field for a table using the below syntax :

db_add_field($ret, 'table_name', 'field_name', array('type' => 'varchar',
             'length' => 255, 'not null' => TRUE,));

What is the syntax for doing a field rename?


Using db_change_field.

Under the parameter section:

$field Name of the field to change.

$field_new New name for the field (set to the same as $field if you don't want to change the name).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.