Welcome Guest, Not a member yet? Register   Sign In
Migrations can't be rolled back
#1

(This post was last modified: 08-26-2017, 07:01 AM by Wouter60.)

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?
Reply
#2

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB