Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

altering type of attribute using yii migration

I have an existing database for web application developed using yii. Now one of the attributes in the table is of type int but I want to convert its type to timestamp in table. How I can achieve this using yii migration so that my web application is affected. I am using Mysql database.

like image 997
prattom Avatar asked Sep 17 '13 05:09

prattom


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 yii?

Because a database structure change often requires some source code changes, Yii supports the so-called database migration feature that allows you to keep track of database changes in terms of database migrations which are version-controlled together with the source code.


1 Answers

create a yii migration and modify the code

public function up(){
$this->alterColumn('table_name', 'column_name', 'new_data_type');//timestamp new_data_type
}

public function down() {
$this->alterColumn('table_name','column_name', 'old_data_type' );//int is old_data_type
}

then migrate up

like image 99
Neophile Avatar answered Sep 23 '22 19:09

Neophile