How can I rename column in laravel using migration?

前端 未结 6 649
名媛妹妹
名媛妹妹 2020-12-04 20:55

I have columns as mentioned bellow:

public function up()
{
    Schema::create(\'stnk\', function(Blueprint $table)
    {
        $table->increments(\'id\         


        
6条回答
  •  南笙
    南笙 (楼主)
    2020-12-04 21:22

    Follow these steps, respectively for rename column migration file.

    1- Is there Doctrine/dbal library in your project. If you don't have run the command first

    composer require doctrine/dbal
    

    2- create update migration file for update old migration file. Warning (need to have the same name)

    php artisan make:migration update_oldFileName_table
    

    for example my old migration file name: create_users_table update file name should : update_users_table

    3- update_oldNameFile_table.php

    Schema::table('users', function (Blueprint $table) {
    $table->renameColumn('from', 'to');
    });
    

    'from' my old column name and 'to' my new column name

    4- Finally run the migrate command

    php artisan migrate
    

    Source link: laravel document

提交回复
热议问题