【发布时间】:2020-05-07 13:58:23
【问题描述】:
我已经检查了其他主题,但没有适合我的解决方案。我最后一次尝试:
public function up()
{
if(Schema::hasColumn('orders_products_variations','id')) {
Schema::table('orders_products_variations',function (Blueprint $table) {
$table->unsignedInteger('id')->change();
$table->dropPrimary();
$table->dropColumn('id');
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('clients', function (Blueprint $table) {
$table->string('id');
});
}
错误信息是:
SQLSTATE[42000]:语法错误或访问冲突:1075 表定义不正确;只能有一个自动列,并且必须定义为一个键(SQL:alter table
orders_products_variationsdrop primary key)
有什么想法吗?
【问题讨论】:
-
听起来
id被定义为自增,所以它必须是主键。您应该能够只删除 id 列而无需任何其他箍。 -
我已经尝试只删除 id 列,但也没有用
-
您可能需要将其拆分为两个
Schema::table调用。第一个将删除主键,而第二个将删除整个列。 -
谢谢,但我也试过了
-
您尝试删除哪一列?