Mitesh Shah
Mitesh Shah

Reputation: 123

Alter column schema of PGSQL not working while alter comment with YIi2

$string = 'User name';
 $default = null; 

Simply from my traits , 
 self::integer()->comment($string)->defaultValue($default)

where $string is 'word' and $default is 'NULL' right now. I have extended SchemaBuilderTrait from /yiisoft/yii2/db/ .

When i am ,

echo self::integer()->comment($string)->defaultValue($default) ;

It result me like , Alter Table User

Alter column "userid" TYPE Integer NULL.

But it should return result me ,

ALTER TABLE "user" ALTER COLUMN "userid" TYPE integer COMMENT "user name";

It works with PHP 5.5.9 in window / linux both but not working with 5.6.21 and even It works with MYSQL in PHP 5.6.21 but not with PGSQL in same PHP version.

// My custom trait code :

<?php
namespace common\models;

use Yii;
use yii\db\SchemaBuilderTrait;

trait AbstractSchemaBuilderTrait 
{
    use SchemaBuilderTrait; 
 public function many2one($table,$column,$rel_table,$rel_column,$type,$size=null,$string=null,$default=null,$act_delete=null,$act_update=null)
    {
        if ($type == 'integer') {
            return self::integer()->comment($string)->defaultValue($default)."  ,ADD CONSTRAINT fk_$table"."_$column FOREIGN KEY($column)  REFERENCES $rel_table($rel_column)";
        }
        return self::$type($size)->comment($string)->defaultValue($default)."  ,ADD CONSTRAINT fk_$table"."_$column FOREIGN KEY($column)  REFERENCES $rel_table($rel_column)";
    }
}
?>

Can anyone Help for this ?

Upvotes: 1

Views: 572

Answers (1)

jlapoutre
jlapoutre

Reputation: 1787

You could use

$this->addCommentOnColumn('{{%tablename}}', 'columname', 'My New Comment');

This is only available as of Yii 2.0.8 though.

Upvotes: 1

Related Questions