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

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.
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."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With