Table of Contents
Inside this article we will see CakePHP 4 How to check migrations status. Article contains classified information about checking the status of migrations using CakePHP CLI command.
Migrations are those files which creates table schema for application. When we create migrations in CakePHP application it stores inside /config/Migrations folder.
Let’s assume few migrations in application for products, employees table, etc.
When we run either migrate for migrations or rollback, status command keep tracks of all activity. This is because it uses phinxlog behind the scene.
Application generates a default table phinxlog in database when run migrations in application. This table stores the migrations which we have migrated in database.
Learn More –
- CakePHP 4 How To Add Column in Table Using Migration
- CakePHP 4 How To Check All Routes of Application
- CakePHP 4 How To Create Migrations For Database
- CakePHP 4 How To Rename Table Using Migration
Let’s get started.
CakePHP 4 Installation
To create a CakePHP project, run this command into your shell or terminal. Make sure composer should be installed in your system.
composer create-project --prefer-dist cakephp/app:~4.0 mycakephp
Above command will creates a project with the name called mycakephp.
Open app_local.php file from /config folder. Search for Datasources. Go to default array of it.
You can add your connection details here to connect with your database. It will be like this –
//... 'Datasources' => [ 'default' => [ 'host' => 'localhost', /* * CakePHP will use the default DB port based on the driver selected * MySQL on MAMP uses port 8889, MAMP users will want to uncomment * the following line and set the port accordingly */ //'port' => 'non_standard_port_number', 'username' => 'root', 'password' => 'sample@123', 'database' => 'mydatabase', /* * If not using the default 'public' schema with the PostgreSQL driver * set it here. */ //'schema' => 'myapp', /* * You can use a DSN string to set the entire configuration */ 'url' => env('DATABASE_URL', null), ], //... //...
You can pass host, username, password and database.
Successfully, you are now connected with the database.
Check Migrations Status
To check status of migrations inside CakePHP application we have a bin/cake console command available.
Open project into terminal, run this command.
$ bin/cake migrations status
It will display a information table where you will see the migration class name, it’s status, etc.
There are two types of migration status
Migration Status – up
“up” indicates that migration file has been migrated to database.
Here, we can see the information about migrations and their respective status. “up” means all these successfully migrated.
Migration Status – down
“down” indicates that migration file yet not migrated to database or it is in pending stage.
Here, inside this screenshot we can see all migrations are with status down. These all migrations are not migrated in database.
When you migrate few migrations and some are pending then you can see status flag with “up” and “down” both into list.
For more about datatypes and other information of migration you can click here for official document.
We hope this article helped you to learn about CakePHP 4 How To Check Migrations Status Tutorial in a very detailed way.
Online Web Tutor invites you to try Skillshare free for 1 month! Learn CakePHP 4, Laravel APIs Development, CodeIgniter 4, Node Js, etc into a depth level. Master the Coding Skills to Become an Expert in Web Development. So, Search your favourite course and enroll now. Click here to join.