Hi,
Today, we will learn how to make migration for change the data type of a column.
I needed to change the type of a column from VARCHAR to TEXT.
First on your terminal write the following comman to make migration file:
php artisan make:migration change_data_type_of_column_in_tablename
This will create a new file named date_change_data_type_of_column_in_tablename.php in database/migrations folder.
Open this file in your editor and write the following script as given.
public function up()
{
DB::statement('ALTER TABLE tablename MODIFY COLUMN columnname TEXT');
}
public function down()
{
DB::statement('ALTER TABLE tablename MODIFY COLUMN columnname VARCHAR(255)');
}
Then on your terminal run the command : php artisan migrate
This will change the given column data type.
Thanks
Today, we will learn how to make migration for change the data type of a column.
I needed to change the type of a column from VARCHAR to TEXT.
First on your terminal write the following comman to make migration file:
php artisan make:migration change_data_type_of_column_in_tablename
This will create a new file named date_change_data_type_of_column_in_tablename.php in database/migrations folder.
Open this file in your editor and write the following script as given.
public function up()
{
DB::statement('ALTER TABLE tablename MODIFY COLUMN columnname TEXT');
}
public function down()
{
DB::statement('ALTER TABLE tablename MODIFY COLUMN columnname VARCHAR(255)');
}
Then on your terminal run the command : php artisan migrate
This will change the given column data type.
Thanks
No comments:
Post a Comment