Migrations - very confusing |
In my application/config/migration.php file, I have the following settings:
PHP Code: $config['migration_enabled'] = TRUE; Now, in my applicatons/migrations folder I have 2 files: 001_do_step1.php 002_do_step2.php Migration step 001 has already run, it adds a field to one of my tables in the database. Now I want to add another field, so I try to run the migration for step 2: migrate/do_migration/002 However, I get the error that I try to add a duplicate field, Code: Error Number: 1060 Why doesn't it migrate using the file that starts with 002 ???
in my app,
my config migration_version is set to 1 and it's run all my 001_* files. did you try to use version 2 ? I use this piece of code PHP Code: $this->load->library('migration');
did your classname is good ?
001_do_step1.php -> class Do_Step1 extends CI_Migration 002_do_step2.php -> class Do_Step2 extends CI_Migration
you can use $this->migration->version(xxx); instead of current()
http://www.codeigniter.com/user_guide/li...n::version
If I rename 001_do_step1.php to 001_do_step1.txt, it works.
Your example still generated the "duplicate field" error, because it calls $this->migration->currunt() twice! I've got it working now with this code: PHP Code: public function do_migrate() I'm still wondering how to do a roll-back. Each migration file has an "up" method and a "down" method. When is the "up" method called?
If you need to roll back, you have to use $this->migration->version(<VERSION>);
So in your case latest version is 2, and you need to go back to 1, you would call $this->migration->version(1); It will automatically call "down" method from 002_do_step2.php. I personally prefer "latest()" - that way I don't have to change $config['migration_version'] each time I need to migrate to a newer version.
One more note: $config['migration_version'] = 0 is the version you want to migrate to. Database has a table called "Migrations" and column "version" lists current version you are on (if it's not there it always defaults to 0!).
|
Welcome Guest, Not a member yet? Register Sign In |