Is the configuration inside .env.testing/.env correct?
Problem With PHPUnit + SQLite dropColumn()
Hello Everyone,
Suddenly all my tests started to fail with the same error.
-
Im using Laravel Framework 7.27.0
-
Ubuntu 20.04
-
PHPUnit in :memory: database and sqlite
-
I did not change any migration and always worked before without problems.
-
If run phpunit on my production server, works, looks like some bad configuration issue
-
If I create blank project and add a dropCOlumn migration works without a problem.
-
If I git reset --hard a week ago (yesterday was working without any problems) I still get errors
Tests\Unit\UserTest::it_has_many_categories
Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 near "1": syntax error (SQL: CREATE TABLE products (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, user_id INTEGER NOT NULL, code VARCHAR(255) NOT NULL COLLATE BINARY, name VARCHAR(255) NOT NULL COLLATE BINARY, slug VARCHAR(255) NOT NULL COLLATE BINARY, description VARCHAR(255) DEFAULT NULL COLLATE BINARY, price NUMERIC(10, 0) NOT NULL, image VARCHAR(255) DEFAULT NULL COLLATE BINARY, active BOOLEAN DEFAULT '1' NOT NULL, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, stock INTEGER DEFAULT 0 NOT NULL, title CLOB DEFAULT NULL COLLATE BINARY, CONSTRAINT 1 FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE))
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Database/Connection.php:631
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Database/Connection.php:465
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Database/Schema/Blueprint.php:102
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php:290
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php:151
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:261
/var/www/atsnacks/database/migrations/2019_10_17_095205_drop_category_id_in_products_table.php:21
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:392
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:401
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:200
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:165
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:110
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:72
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:541
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:81
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:37
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Container/Util.php:37
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:95
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:39
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Container/Container.php:596
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Console/Command.php:134
/var/www/atsnacks/vendor/symfony/console/Command/Command.php:258
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Console/Command.php:121
/var/www/atsnacks/vendor/symfony/console/Application.php:916
/var/www/atsnacks/vendor/symfony/console/Application.php:264
/var/www/atsnacks/vendor/symfony/console/Application.php:140
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Console/Application.php:93
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Console/Application.php:185
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:263
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Testing/PendingCommand.php:171
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Testing/PendingCommand.php:291
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithConsole.php:52
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Foundation/Testing/RefreshDatabase.php:40
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Foundation/Testing/RefreshDatabase.php:17
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:115
/var/www/atsnacks/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:84
Here is my migration file from the error. If I full comment this migration the error goes to the next dropColumn migration. As I could see. The column got dropped but then fails for some reason.
class DropCategoryIdInProductsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('products', function (Blueprint $table) {
if(DB::connection()->getDatabaseName() != ':memory:'){
$table->dropForeign('products_category_id_foreign');
}
$table->dropColumn('category_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('products', function (Blueprint $table) {
$table->unsignedBigInteger('category_id')->index();
$table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
});
}
Anyone has an Idea what can be? Thanks in advance.
After 14 Hours I managed to fix the problem by downgrading dbal/doctine version from 2.10.13 to 2.10.12 in composer.json
"doctrine/dbal": "2.10.2"
The doctrine 2.10.3 for some reason cant find well the foreign key name at line 2586 in file /vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php returning 1 or 0 on getQuotedName method
if (strlen($foreignKey->getName())) {
$sql .= 'CONSTRAINT ' . $foreignKey->getQuotedName($this) . ' ';
}
Please or to participate in this conversation.