Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to drop column with laravel migration on sqlite?

I want to write test for my application, but i getting error when run the migration;

There is no column with name

My Migration file

Schema::table('bill_payments', function (Blueprint $table) {
    $table->dropColumn('attachment');
    // $table->getColumns(); return empty array
    // $table->dropColumn(['attachment']); I tried this
});

dd(Schema::hasColumn('bill_payments', 'attachment')); // Return false

// and this is not working because return false.

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

Also i add doctrine/dbal 2.5.13

i running tests using mysql, but slowly.

[Solved]

Wow! i using prefix for tables. i deleted this and now it's work.

like image 348
Berkay Avatar asked Nov 30 '25 01:11

Berkay


1 Answers

One thing you need to know about migrations is that they run untill they crash or succeed, following your example:

Schema::table('bill_payments', function (Blueprint $table) {
    $table->dropColumn('attachment');
});
//It will drop the column and stop here. When you run the migration again, it will output your error because the column no longer exists.
dd(Schema::hasColumn('bill_payments', 'attachment')); // Return false

What you should have in your migration code is having the reverse operations in the Down() method. Meaning you run the migration, it applies the Up() and when you rollback, it reverts correctly. That error is really what it means, it means that when it reaches an operation relating table bill_payments and column attachment, it recognizes that attachment doesn't exist.

Edit:

There is something related to SQlite in the documentation:

"Dropping or modifying multiple columns within a single migration while using a SQLite database is not supported."

like image 76
abr Avatar answered Dec 02 '25 15:12

abr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!