DEV Community

Khandokar Nafis Jaman
Khandokar Nafis Jaman

Posted on

Rename column name in laravel migration

If you want to change the columns name of an existing table, at first you need to write the following way. Suppose we have a table name users . So we need to run the following command first.

php artisan make:migration rename_description_to_content_on_users_table --table=users
Enter fullscreen mode Exit fullscreen mode

then, a new migration file will be created. Let's say, there is a column name description. I want to change this name to 'bio'. So now, I need to edit the migration file like this.

        Schema::table('users', function (Blueprint $table) {
            //
            $table->renameColumn('description', 'bio');
        });

Enter fullscreen mode Exit fullscreen mode

Then run, php artisan migrate command. And done!

Thanks. Happy coding!

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

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

Okay