Welcome Guest, Not a member yet? Register   Sign In
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




Theme © iAndrew 2016 - Forum software by © MyBB