Database Migrations in CodeIgniter — a practical guide to CodeIgniter migrations with clear examples you can reuse in real projects.
CodeIgniter Tutorial Series (33/74). Prefer one article? Read the complete CodeIgniter tutorial.
Short description
Migrations keep schema changes repeatable across machines and environments.
Create & run migration
php spark make:migration CreatePostsTable
php spark migrate
php spark migrate:rollback
Migration up()
$this->forge->addField([
'id' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
'title' => ['type' => 'VARCHAR', 'constraint' => 255],
'created_at' => ['type' => 'DATETIME', 'null' => true],
]);
$this->forge->addKey('id', true);
$this->forge->createTable('posts');