Add comment to SQL table

1.2k Views Asked by At

How can I add comment for specific SQL-table in Yii2 migration?

SQL code:

ALTER TABLE my_table COMMENT 'Hello World'

I wand to do in within a migration in ORM way

2

There are 2 best solutions below

0
On BEST ANSWER

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');
0
On

Currently there is no such functionality in Yii 2 migrations.

You have to write it in plain SQL via execute() method:

$this->execute("ALTER TABLE my_table COMMENT 'Hello World'");