Fields are created via an associative array. Within the array you must
include a ‘type’ key that relates to the datatype of the field. For
example, INT, VARCHAR, TEXT, etc. Many datatypes (for example VARCHAR)
also require a ‘constraint’ key.

$fields=array('users'=>array('type'=>'VARCHAR','constraint'=>'100',),);// will translate to "users VARCHAR(100)" when the field is added.

Additionally, the following key/values can be used:

unsigned/true : to generate “UNSIGNED” in the field definition.

default/value : to generate a default value in the field definition.

null/true : to generate “NULL” in the field definition. Without this,
the field will default to “NOT NULL”.

auto_increment/true : generates an auto_increment flag on the
field. Note that the field type must be a type that supports this,
such as integer.

$fields=array('blog_id'=>array('type'=>'INT','constraint'=>5,'unsigned'=>TRUE,'auto_increment'=>TRUE),'blog_title'=>array('type'=>'VARCHAR','constraint'=>'100',),'blog_author'=>array('type'=>'VARCHAR','constraint'=>'100','default'=>'King of Town',),'blog_description'=>array('type'=>'TEXT','null'=>TRUE,),);

After the fields have been defined, they can be added using
$this->dbforge->add_field($fields); followed by a call to the
create_table() method.

Generally speaking, you’ll want your table to have Keys. This is
accomplished with $this->dbforge->add_key(‘field’). An optional second
parameter set to TRUE will make it a primary key. Note that add_key()
must be followed by a call to create_table().

Multiple column non-primary keys must be sent as an array. Sample output
below is for MySQL.

If you are using MySQL or CUBIRD, then you can take advantage of their
AFTER and FIRST clauses to position the new column.

Examples:

// Will place the new column after the `another_field` column:$fields=array('preferences'=>array('type'=>'TEXT','after'=>'another_field'));// Will place the new column at the start of the table definition:$fields=array('preferences'=>array('type'=>'TEXT','first'=>TRUE));

The usage of this method is identical to add_column(), except it
alters an existing column rather than adding a new one. In order to
change the name you can add a “name” key into the field defining array.