CodeIgniter Forums
can't add columns to existing table with migration - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: can't add columns to existing table with migration (/showthread.php?tid=75380)



can't add columns to existing table with migration - codemicky - 01-31-2020

migration file: 242_version_242.php



Code:
<?php

defined('BASEPATH') or exit('No direct script access allowed');

class Migration_Version_242 extends CI_Migration
{
    public function __construct()
    {
        parent::__construct();
    }

    public function up()
    {
      $fields = array(
        'monitoring' => array(
          'type' => 'INT',
          'default' => NULL
        ),
        'signatory' => array(
          'type' => 'INT',
          'default' => NULL
        )
      );

      $this->dbforge->add_column('contracts', $fields);
    }
}

controller file: Migration.php


Code:
class Migration extends App_Controller
{
    public function add($version)
    {
      // load migration library
      $this->load->library('migration');

      if(!$this->migration->version($version)){
        show_error($this->migration->error_string());
      } else {
        echo "Migration has been run successfully.";
      }
    }
}

I have run http://localhost:8080/migration/add/242 to run a migration.

I am seeing Migration has been run successfully but the columns were not added.

I have checked that the contracts table exists.

Also, I have checked the application/config/migration file.

Code:
$config['migration_version'] = 242;
$config['migration_type'] = 'sequential';
$config['migration_enabled'] = true;

Can anyone help to fix this issue?