Laravel迁移命令无序运行

时间:2016-11-03 17:54:24

标签: php laravel database-migration

我在Laravel 4.2中进行了以下迁移:

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class ChangeProductDecimalFields extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('products', function(Blueprint $table)
        {
            $table->dropColumn(['price', 'cost_price', 'retail_price', 'sale_price', 'weight', 'width', 'height', 'depth']);
            $table->decimal('price', 10, 4)->after('availability_description');
            $table->decimal('cost_price', 10, 4)->after('price');
            $table->decimal('retail_price', 10, 4)->after('cost_price');
            $table->decimal('sale_price', 10, 4)->after('retail_price');
            $table->decimal('weight', 10, 4)->after('sale_price');
            $table->decimal('width', 10, 4)->after('weight');
            $table->decimal('height', 10, 4)->after('width');
            $table->decimal('depth', 10, 4)->after('height');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('products', function(Blueprint $table)
        {
            $table->dropColumn(['price', 'cost_price', 'retail_price', 'sale_price', 'weight', 'width', 'height', 'depth']);
            $table->decimal('price',  10, 2)->after('availability_description');
            $table->decimal('cost_price',  10, 2)->after('price');
            $table->decimal('retail_price',  10, 2)->after('cost_price');
            $table->decimal('sale_price',  10, 2)->after('retail_price');
            $table->decimal('weight',  10, 2)->after('sale_price');
            $table->decimal('width',  10, 2)->after('weight');
            $table->decimal('height',  10, 2)->after('width');
            $table->decimal('depth',  10, 2)->after('height');
        });
    }

}

当我运行php artisan migrate --pretend时,添加列的命令在dropColumn命令之前运行。这是输出:

ChangeProductDecimalFields: alter table `products` add `price` decimal(10, 4) not null after `availability_description`, add `cost_price` decimal(10, 4) not null after `price`, add `retail_price` decimal(10, 4) not null after `cost_price`, add `sale_price` decimal(10, 4) not null after `retail_price`, add `weight` decimal(10, 4) not null after `sale_price`, add `width` decimal(10, 4) not null after `weight`, add `height` decimal(10, 4) not null after `width`, add `depth` decimal(10, 4) not null after `height`
ChangeProductDecimalFields: alter table `products` drop `price`, drop `cost_price`, drop `retail_price`, drop `sale_price`, drop `weight`, drop `width`, drop `height`, drop `depth`

显然,这会导致错误,因为它正在尝试创建已存在的列。为什么Laravel不首先删除迁移中定义的列?

0 个答案:

没有答案