DEV Community

ilya
ilya

Posted on

1 1

Rename column in laravel migration

php artisan make:migration rename_fields_to_chat_messages_table --table=chat_message
You can created migration file with above command.
You can rename column as follow.

public function up()
{
    Schema::table('chat_message', function (Blueprint $table) {
        $table->renameColumn('created_date', 'created_at');
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::table('chat_message', function (Blueprint $table) {
        $table->renameColumn('created_at', 'created_date');
    });
}
Enter fullscreen mode Exit fullscreen mode

you can update as follow

public function up()
{
Schema::table('chat_message', function (Blueprint $table) {
$table->unsignedInteger('user_id')->change();
$table->unsignedInteger('doc_id')->change();
$table->unsignedInteger('created_by')->nullable();
$table->unsignedInteger('updated_by')->nullable()->after('created_by');
$table->timestamp('created_at')->nullable()->change();
$table->timestamp('updated_at')->nullable()->after('created_at');
});
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::table('chat_message', function (Blueprint $table) {
        $table->dateTime('created_date')->change();
        $table->dropColumn('created_by');
        $table->dropColumn('updated_by');
        $table->dropColumn('updated_at');
    });
}
Enter fullscreen mode Exit fullscreen mode

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Heroku

This site is powered by Heroku

Heroku was created by developers, for developers. Get started today and find out why Heroku has been the platform of choice for brands like DEV for over a decade.

Sign Up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay