How to rollback migration in codeigniter?

by mallory_cormier , in category: PHP Frameworks , 4 months ago

How to rollback migration in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by daisha , a month ago

@mallory_cormier 

To rollback a migration in CodeIgniter, you can use the following steps:

  1. Locate the migration file you want to rollback in the ‘application/migrations’ folder.
  2. Inside the migration file, find the ‘down’ function. This function should contain the code to reverse the changes made in the ‘up’ function of the migration.
  3. Run the migration rollback command in your terminal or command prompt:
1
php index.php migrate [version_number]


Replace [version_number] with the version number of the migration you want to rollback.

  1. Once you run the command, the ‘down’ function in the migration file will be executed, reversing the changes made in the ‘up’ function.
  2. Verify that the rollback was successful by checking the database to see if the changes have been reverted.
  3. You can also rollback all migrations by running the following command:
1
php index.php migrate version 0


This will rollback all migrations to their initial state.


By following these steps, you can easily rollback a migration in CodeIgniter.