Migrations and Seeders
π CodeIgniter
π 37 views
π
Dec 22, 2025
β± Estimated reading time: 2 min
Migrations and Seeders in CodeIgniter (CodeIgniter 4)
Migrations and Seeders help you manage database structure and data programmatically, making your project easy to version, share, and deploy.
1. Migrations
What Is a Migration?
-
A PHP file that defines database schema changes
-
Version control for your database
-
Allows easy rollback and updates
Migration Location
Creating a Migration
Migration Example
Running Migrations
Rollback:
Migration Status
2. Seeders
What Is a Seeder?
-
Inserts sample or default data into tables
-
Useful for testing and development
Seeder Location
Creating a Seeder
Seeder Example
Running Seeders
Running Multiple Seeders
3. Enable Migrations
In .env:
In app/Config/Migrations.php:
4. Best Practices
β
Use migrations for all schema changes
β
Never edit DB manually in production
β
Seed only non-sensitive data
β Donβt use seeders for production user data
5. Migrations vs Seeders
| Feature | Migrations | Seeders |
|---|---|---|
| Purpose | DB structure | DB data |
| Versioned | Yes | No |
| Rollback | Yes | No |
Summary
-
Migrations manage database schema
-
Seeders populate initial/sample data
-
Essential for teamwork and deployment
-
Fully supported via Spark CLI
π Some advanced sections are available for Registered Members
Register Now
Register Now
Share this Post
β Back to Tutorials