I am trying to change column data type using laravel 5.6.
I have a table in which two columns have a data type of text
but I would like to change it to longtext
. I have tried following:
composer require doctrine/dbal
composer dump-autoload
...and then created the migration 2019_12_23_065820_change_response_column_data_type_in_log_requests_table.php
for log_requests
table.
...and then the following script
public function up()
{
Schema::table('log_requests', function (Blueprint $table) {
$table->longText('request')->nullable()->change();
$table->longText('response')->nullable()->change();
});
}
But it is not changing the column's data type. Can someone guide me? Where am I wrong so that I can fix it? Thank you.
EDITED
After requesting for migration in comment, I added migration script:
public function up()
{
Schema::create('log_requests', function (Blueprint $table) {
$table->increments('id');
$table->bigInteger('user_id')->nullable()->unsigned();
$table->string('api_name')->nullable();
$table->string('url')->nullable();
$table->string('method')->nullable();
$table->string('ip_address')->nullable();
$table->string('status_code')->nullable();
$table->string('duration')->nullable();
$table->text('request')->nullable();
$table->text('response')->nullable();
$table->timestamps();
});
}
To rename a column, you may use the renameColumn method on the Schema builder. Before renaming a column, be sure to add the doctrine/dbal dependency to your composer. json file: Schema::table('users', function (Blueprint $table) { $table->renameColumn('from', 'to'); });
A foreign key is a field that is used to establish the relationship between two tables via the primary key (You can also use a non-primary field but not recommended). In this tutorial, I show how you can add a foreign key constraint while creating a table using migration in the Laravel 8 project.
Just change the column comment, for example:
$table->mediumText('myColumn')->comment(' ')->change(); // up
$table->text('myColumn')->comment('')->change(); // down
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