Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change column data type in laravel 5.6?

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:

  • executed composer require doctrine/dbal
  • executed 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();
    });
}
like image 220
Imran Abbas Avatar asked Dec 23 '19 07:12

Imran Abbas


People also ask

How do I rename a column in Laravel?

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'); });

What is foreign key in Laravel?

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.


Video Answer


1 Answers

Just change the column comment, for example:

$table->mediumText('myColumn')->comment(' ')->change(); // up
$table->text('myColumn')->comment('')->change(); // down
like image 57
Immeyti Avatar answered Nov 02 '22 06:11

Immeyti