How can I rename column in laravel using migration?

前端 未结 6 644
名媛妹妹
名媛妹妹 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:11

    You need to create another migration file - and place it in there:

    Run

    Laravel 4:    php artisan migrate:make rename_stnk_column
    Laravel 5:    php artisan make:migration rename_stnk_column
    

    Then inside the new migration file place:

    class RenameStnkColumn extends Migration
    {
    
        public function up()
        {
            Schema::table('stnk', function(Blueprint $table) {
                $table->renameColumn('id', 'id_stnk');
            });
        }
    
    
        public function down()
        {
            Schema::table('stnk', function(Blueprint $table) {
                $table->renameColumn('id_stnk', 'id');
            });
        }
    
    }
    

提交回复
热议问题