• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dbforge alter add column always create NOT NULL field

#1
Hi!

The query of ALTER TABLE ADD COLUMN is automatically concatened by NOT NULL in CodeIgniter working with PostgreSQL

PHP Code:
$this->dbforge = new CI_DB_postgre_forge;
$sql $this->dbforge->_alter_table('ADD',
 
                   'data.circuits',
 
                   'location',
 
                   'integer');
$this->db->query($sql); 

So I always got an error message when there is already data inside the table: i'm using a french computer

ERREUR: la colonne « location » contient des valeurs NULL
ALTER TABLE "data"."circuits" ADD "location" integer NOT NULL

How to avoid this ?
Reply

#2
I don't know if it is a bug but I add these lines when I call for add_column or _alter_table() now:
PHP Code:
if (substr($sql, -88) == "NOT NULL") {
 
   $sql substr_replace($sql'', -88);


Remove the last NOT NULL text in CodeIgniter-built query
Reply

#3
https://codeigniter.com/userguide2/database/forge.html

PHP Code:
$field = array(
    
'location' => array(
        
'type' => 'integer'
        
'null' => false,
    ),
);

$this->load->dbforge();
$this->dbforge->add_column('data.circuits'$field); 

You shouldn't be calling _alter_table() directly, but, if you need to call it directly for some reason, you should look at the function definition, because the ~6th argument controls whether the field is defined with ' NULL' or ' NOT NULL'.
Reply

#4
Thanks for your return. I am newbie with CI so I didn't dare to step inside CI system codes!
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.