Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
CodeIgniter

Database Migrations in CodeIgniter

Version your database schema with migrations using php spark migrate.

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');

Leave a reply

Your email address will not be published. Required fields are marked *