Need support for InnoDB in migrations #41

bitbucket-import opened this Issue Aug 19, 2011 · 2 comments


None yet

4 participants


The migrations should have a way to specify a table type of InnoDB in order to enforce foreign key support on mysql / mysqli. I was able to hack it in by changing line 180 of the mysqli/mysqli_forge.php from

$sql .= "\n) DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};";


$sql .= "\n) ENGINE=InnoDB DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};";

but thats an ugly hack. Perhaps something like

if ( ! $this->db->table_exists('my_innodb_table'))

    // Setup Keys
    $this->dbforge->add_key('id', TRUE);

        'id' => array('type' => 'INT', 'constraint' => 5, 'unsigned' => TRUE, 'auto_increment' => TRUE),
        'account_id' => array('type' => 'INT', 'constraint' => '5', 'unsigned' => TRUE, 'null' => FALSE),
        'category_id' => array('type' => 'INT', 'constraint' => '5', 'unsigned' => TRUE, 'null' => FALSE),
    $this->dbforge->add_field("CONSTRAINT FOREIGN KEY (account_id) REFERENCES accounts(id)");


    $this->dbforge->create_table('categories', TRUE);

I know foreign key support is a pain, but it's easily done with

$this->dbforge->add_field("CONSTRAINT FOREIGN KEY (account_id) REFERENCES accounts(id)");

now we just need support for InnoDB to really make migrations useful.

@MunGell MunGell added a commit that referenced this issue Jan 27, 2012
@MunGell MunGell Change table engine for MySQL database, issue #41
Small functions to allow developers choose table engines. Works with
MySQL and MySQLi drivers (other ignore it).

If you need features dbforge doesn't support (most notably innodb and FK constraints) then you can fall back to db->query('SQL').

@narfbg narfbg added a commit that referenced this issue Jan 20, 2014
@narfbg narfbg Add support for optional table attributes to CI_DB_forge::create_table()
Supersedes PRs #989, #2776
Related issue: #41

Anybody who wants this feature, please test the above commit from the feature/dbforge_table_attributes branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment