CodeIgniter Forums
Migrations can't be rolled back - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Migrations can't be rolled back (/showthread.php?tid=68795)



Migrations can't be rolled back - Wouter60 - 08-26-2017

I'm trying to set up a controller for running migrations, and - if necessary - rolling them back.

In the migrations config I have these settings:
PHP Code:
$config['migration_enabled'] = TRUE;
$config['migration_type'] = 'timestamp';
$config['migration_table'] = 'migrations';
$config['migration_auto_latest'] = FALSE;
$config['migration_version'] = '20170826141700' //this is the first migration I need to run
$config['migration_path'] = APPPATH.'migrations/'

I have a file named "20170826141700_create_eventlog_table.php" in application/migrations.
This file has a class named "Migration_Create_eventlog_table" with 2 functions: up() and down().
The up function creates a table ('eventlog') in my database.
The down function drops this table.

If I run $this->migration->latest(), it returns TRUE.
The eventlog table is created succesfully. So far, so good.

However, the migrations table remains empty. The version number of the latest migration isn't saved.
As a result of this, I can't rollback this migration.
How can I get this working?


RE: Migrations can't be rolled back - Wouter60 - 08-26-2017

Partly solved it myself.
I deleted the migrations table and ran the first migration again.
This time, the version number DID appear in the table.
Rolling back also works now, despite of the fact that $this->migrations->version(0) returns FALSE.
My eventlog table is being deleted by the down() function in the migration class.

Still wondering what to put in the migration config file.
Initially $config['migration_version'] had value 0.
I changed it to
PHP Code:
$config['migration_version'] = '20170826141700'

Should I set it back to 0 before I start the rollback ?
It's pretty confusing, and the CI documentation is not very clear on this subject.