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.
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"
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With