title: Codeigniter Migration to Alter a Table
body: <p>I have crated a Migration in codeigniter to create a MySQL table with 4 columns. Now I want to change the name of one of the columns without losing the data in that table.</p>
  
  <p>First, I have enabled migration &amp; set the version to 1.
  Then, I have created a <code>file 001_create_users.php</code> and added the following code.</p>
  
  <pre><code>class Migration_Create_users extends CI_Migration {
  
      public function up(){
  
          $this-&gt;dbforge-&gt;add_field(
              array(
                  'id'        =&gt; array('type'=&gt;'INT', 'constraint'=&gt;11, 'unsigned'=&gt;TRUE, 'auto_increment'=&gt;TRUE),
                  'email'     =&gt; array('type'=&gt;'VARCHAR', 'constraint'=&gt;100),
                  'password'  =&gt; array('type'=&gt;'VARCHAR', 'constraint'=&gt;255),
                  'created'      =&gt; array('type'=&gt;"TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
              )
          );
  
          $this-&gt;dbforge-&gt;add_key('id');
          $this-&gt;dbforge-&gt;create_table('users');
  
      }
  
      public function down(){
  
          $this-&gt;dbforge-&gt;drop_table('users');
  
      }
  }
  </code></pre>
  
  <p>Now I want to change the column name '<code>date</code>' to '<code>created_at</code>'. So how should I do it? I mean what is the best way to do it? 
  Also can anyone explain me how to do a rollback? Because I have used the folwing controller to run the migration. </p>
  
  <pre><code>class Migration extends Admin_Controller{
  
      public function __construct(){
          parent::__construct();
      }
  
      public function index($version){
  
          $this-&gt;load-&gt;library('migration');
  
          if( !$this-&gt;migration-&gt;version($version)){
              show_error($this-&gt;migration-&gt;error_string());
          }
          echo "I'm in Migration";
      }
  
  }
  </code></pre>
  
  <p>So, If I run <a href="http://localhost/migration/index/1" rel="nofollow noreferrer">http://localhost/migration/index/1</a> It will run the up() function. What should I do to perform a rollback via browser? Can I create another method and call it?</p>
  
  <p>I still do not understand how the migration actually works, Can anyone please explain it to me?</p>