Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 Migration to increase column length

Tags:

mysql

schema

yii2

In Yii2 I wish to create a migration to change the character limit of a varchar column from 255 to 765.

Using $this->alterColumn('my_table', 'text_column', 'string');will make the column 255 as is. I'm thinking of using mysql to change the column to TEXT instead of Varchar, but is there a way to do this in Yii2?

like image 842
mrateb Avatar asked Jun 05 '18 12:06

mrateb


People also ask

How do I run a specific migration in yii2?

To run specific migration, you can mark(skip) migrations upto just before one you want run. You can mark migration by using one of following command: Using timestamp to specify the migration yii migrate/mark 150101_185401. Using a string that can be parsed by strtotime() yii migrate/mark "2015-01-01 18:54:01"

What is migration in yii2?

Migration is the base class for representing a database migration. Migration is designed to be used together with the "yii migrate" command. Each child class of Migration represents an individual database migration which is identified by the child class name.


1 Answers

Changing varchar length:

$this->alterColumn('my_table', 'text_column', $this->string(765));

Changing column type to text:

$this->alterColumn('my_table', 'text_column', $this->text());

You can find more examples in Migrations documentation.

like image 123
rob006 Avatar answered Oct 14 '22 15:10

rob006