Welcome Guest, Not a member yet? Register   Sign In
forge->addColumn
#1

Hi All,

CI 4.6.1.

I am trying to add a new column to an existing table. I am not having any luck.


PHP Code:
        $val                  = array();
        $obj['email_private'] = $this->getEmailField();
        $val                  $obj['email_private'] + ['after' => 'email_public'];
        $this->forge->addColumn('entry_requests'$val); 


getEmailFields looks like


PHP Code:
    protected function getEmailField()
    {
        $str = ['type' => 'VARCHAR''constraint' => '128''DEFAULT' => ' ''null' => 'false',];
        return $str;
    // end of method 

The error I am getting is an exception inside forge->addField. It seems that for some reason, it doesn't like the VARCHAR part of the definition. It throws a "Field information is required for that operation." exception, from line 387.

The variable $val contains:
  • type = "VARCHAR"
  • constraint = "128"
  • DEFAULT = " "
  • null = "false"
  • after = "email_public"

I don't see what I have done wrong and cannot find the error on the internet to track it down further.

Any help is much appreciated.
Reply
#2

I'm not understanding the majority of what your code does, but here is what it looks like in the simplest form to do what I think you're trying to achieve (try it and report back):
PHP Code:
$this->forge->addColumn('entry_requests', [ //'entry_requests' is the table name
 
'email_private' => [ // the column name needs to be the key of the passed array
 
'type' => 'VARCHAR',
 
'constraint' => 128// 128 should be an int type (check the docs)
 
'default' => ''// keys are case-sensitive (check the docs); empty string as opposed to space
 
'null' => false// false should be boolean type (check the docs)
 
'after' => 'email_public'// the column after which to insert new 'email_private' column
 
],
]); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB