Codeigniter Migration

Use migration to update database structure in more systematic way. For CI version 3.x

Setting up

  1. Create migration directory – application/migrations
  2. Update setting application/config/migration.php
    1. set $config[‘migration_type’] = ‘sequential’
  3. Create table “migrations” in database. With 1 field named “version” of type INT(11)
  4. Add controller “Migration” in application/controllers directory

To use

  1. after add the migration file in application/migrations directory,
  2. update version number to latest version in config/migration.php
  3. run migration script https://your_domain/migrate

Other notes and references

  1. Migration file name should be 001_add_users.php (sequence_number+operation+tablename)
  2. use dbforge class to construct the migration file

Leave a Reply

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