0
votes

I have already checked the other topics but no solution worked with me. I tried the last time:

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');
    });
}

And the error message is :

SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key (SQL: alter table orders_products_variations drop primary key)

Any idea?

1
Sounds like id is defined as auto increment, so it must be the primary key. You should be able to just drop the id column without any of the other hoops.aynber
i already tried to drop only the id column but it didn't work tooLucasLaurens
You might have to split this up into two Schema::table calls. The first will drop the primary key, while the second drops the entire column.PtrTon
Thx but i have also triedLucasLaurens
Wich column you try to delete ?Foued MOUSSI

1 Answers

0
votes

A migration class contains two methods: up and down. The up method is used to add new tables, columns, or indexes to your database, while the down method should reverse the operations performed by the up method.

Dropping Columns

To drop a column, use the dropColumn on the Schema builder inside down method

if (Schema::hasColumn('table_name', 'column_name')) {
    Schema::table('table_name', function (Blueprint $table) {
       $table->dropColumn('column_name');
    });
}

Adding / Dropping Columns

PS When you have to add a new column to the existing table in Laravel, you must create new migration .

php artisan make:migration add_column_to_table