I have a Laravel project with a MySQL database, and my migration works perfectly, but my problem is when I change the MySQL connection to SQLite and run the migration, I get an error for fields that do not have a default value. What is the solution for this? I found this solution for that is dirty, and I have to add this condition to many migrations.
$driver = Schema::connection($this->getConnection())
->getConnection()->getDriverName();
Schema::table('proposals', function (Blueprint $table) use ($driver) {
if ($driver === 'sqlite') {
$table->unsignedBigInteger('final_amount')->default('');
} else {
$table->unsignedBigInteger('final_amount');
}
});
Error
SQLSTATE[HY000]: General error: 1 Cannot add a NOT NULL column with default value NULL
unsignedBigIntegerbut you set default to empty string? try use 0 instead.