PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, April 13, 2022

[FIXED] How can we add column in existing table with migration in CodeIgniter 3

 April 13, 2022     codeigniter, codeigniter-3, database, migration, mysql     No comments   

Issue


<?php

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

class Migration_Add_dummy_field_to_blog_table  extends CI_Migration {

        public function up()
        {
                $fields = array(
                        'dummy' => array('type' => 'TEXT')
                );
                $this->dbforge->add_column('blog', $fields);
        }

        public function down()
        {
                $this->dbforge->drop_column('blog', 'dummy');
        }
}

Solution

First of all you need to set constraint and then specify the place where you want to add the column. Try this:

public function up()
        {
                $fields = array(
                        'dummy' => array(
                                 'type' => 'varchar'
                                 'constraint' => 100,
                                 'after' => 'username'
                    )
                );
                $this->dbforge->add_column('blog', $fields);
        }


Answered By - Saqib Ali
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing