What are Migrations in CodeIgniter 4?
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.
Previous
What is the Security class in CodeIgniter 4?
Next
What are Database Seeders in CodeIgniter 4?