![]() |
Migrations - very confusing - 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 - very confusing (/showthread.php?tid=64309) |
Migrations - very confusing - Wouter60 - 02-05-2016 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 ??? RE: Migrations - very confusing - keulu - 02-05-2016 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'); RE: Migrations - very confusing - Wouter60 - 02-05-2016 Yes I did. Has no effect. I'm really puzzled by this. RE: Migrations - very confusing - keulu - 02-05-2016 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 RE: Migrations - very confusing - keulu - 02-05-2016 you can use $this->migration->version(xxx); instead of current() http://www.codeigniter.com/user_guide/libraries/migration.html?highlight=migration#CI_Migration::version RE: Migrations - very confusing - Wouter60 - 02-05-2016 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? RE: Migrations - very confusing - siburny - 02-09-2016 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. RE: Migrations - very confusing - siburny - 02-09-2016 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!). RE: Migrations - very confusing - LexXx - 05-31-2016 This video can help you. [Video: https://youtu.be/i07XXM37VFk] |