Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add comment to SQL table

Tags:

migration

yii2

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

like image 435
megapixel23 Avatar asked Nov 28 '25 05:11

megapixel23


2 Answers

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');
like image 93
Yasar Arafath Avatar answered Nov 30 '25 00:11

Yasar Arafath


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'");
like image 21
arogachev Avatar answered Nov 29 '25 22:11

arogachev