<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class RemoveConstructionDateToOrdersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (Schema::hasColumn('orders', 'construction_date')) {
Schema::table('orders', function (Blueprint $table) {
$table->dropColumn('construction_date');
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('orders', function (Blueprint $table) {
$table->date('construction_date');
});
}
}
当我在sqlite数据库上迁移这个laravel迁移时,我得到了以下错误。
InvalidArgumentException:需要字符串作为索引列
2条答案
按热度按时间9q78igpj1#
经过几个小时的摸索,我找到了问题所在。看起来像是doctrine/dbal包无法重命名/handle/drop?!SQLite列已经有索引
因此,我的解决方案是不对后来在迁移中重命名的列创建任何索引
当然,我们确实希望索引存在于MySQL中,所以这里是我的解决方案。
因此,当您稍后尝试重命名列并使用SQLite时,它可以工作。
e5njpo682#
SQLite不支持在一次修改中多次调用dropColumn / renameColumn。
回顾您的迁移文件,并将dropColumn / renameColumn分离到它们自己的修改块中。