What are Migrations in CodeIgniter 4?

Why Interviewers Ask This

This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex CodeIgniter topics. It also reveals how well you can explain technical ideas to non-experts.

Answer

CodeIgniter 4 has a built-in Migration system for version-controlling your database schema. Create a migration: php spark make:migration CreateUsersTable. Migrations live in app/Database/Migrations/ with timestamps in the filename. Each migration has up() (apply changes) and down() (rollback) methods using the Forge class: $this->forge->addField(["id" => ["type" => "INT", "auto_increment" => true], "name" => ["type" => "VARCHAR", "constraint" => 100]])->addKey("id", true)->createTable("users"). Run: php spark migrate. Rollback: php spark migrate:rollback. Status: php spark migrate:status. Refresh (rollback all and re-run): php spark migrate:refresh. Migration state is stored in the migrations table.

Pro Tip

If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.