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


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',

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 ?

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


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


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'.

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

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

Users browsing this thread:
1 Guest(s)

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