Welcome Guest, Not a member yet? Register   Sign In
Database migrations: add_field vs add_column
#1

[eluser]malzahar[/eluser]
When creating database migrations is there really a difference between add_field and add_column. I know create_table is supposed to be used after add_field and conversely add_column is only for existing tables. So would there be a real difference between the following.

Code:
$fields = array(
   'id' => array(
      'type' => 'INT',
      'constraint' => 11,
      'unsigned' => TRUE,
      'auto_increment' => TRUE
   ),
   'username' => array(
      'type' => 'VARCHAR',
      'constraint' => 40
   ),
   'password' => array(
      'type' => VARCHAR',
      'constraint' => 60
   )
);
$this->dbforge->add_field($fields);
$this->dbforge->create_table('users');

and

Code:
$this->dbforge->create_table('users');
$fields = array(
   'id' => array(
      'type' => 'INT',
      'constraint' => 11,
      'unsigned' => TRUE,
      'auto_increment' => TRUE
   ),
   'username' => array(
      'type' => 'VARCHAR',
      'constraint' => 40
   ),
   'password' => array(
      'type' => VARCHAR',
      'constraint' => 60
   )
);
$this->dbforge->add_column('users', $fields);




Theme © iAndrew 2016 - Forum software by © MyBB