Tebe
Tebe

Reputation: 3214

Yii migration addColumn - add explaining comment

I've no problems with migrations in Yii. But one things bothers me a lot.

I can't manage to add comment to it.

    public function safeUp()
    {
       $this->addColumn('product_supplier', 'type_search', "'INT(1) DEFAULT \'0\'' COMMENT  'field hohohoho'  ");
    }

In phpmyadmin I used to add comments in such way:

enter image description here

This feature helps a lot to support project.

I would like to be able to do comments in migrations.

Everything what I found is this post:

enter image description here

But I need to add comment in addColumn function. Because I already have the table. Recreating it is not a option because I would lose all data in it.

Maybe someone can guess the proper syntax?

Thanks.

Upvotes: 4

Views: 2666

Answers (2)

Yasar Arafath
Yasar Arafath

Reputation: 625

In yii2 format

  • addCommentOnColumn($table, $column, $comment)
  • dropCommentFromColumn($table, $column)
  • addCommentOnTable($table, $comment)
  • dropCommentFromTable($table)

Example: In migration file

$this->addCommentOnColumn('user','role_id','Relation table of role');

Upvotes: 5

Tebe
Tebe

Reputation: 3214

Ok, it was pretty straightforward:

        $this->createTable('order',[

       'user_margin_user_id' =>  'INT(32) DEFAULT \'0\'  COMMENT "EXPLAINING COMMENT"',    

    ], 'ENGINE=InnoDB CHARSET=utf8');

Upvotes: 1

Related Questions