-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Description
Actually it is possible to define a NOT NULL
column while creating a table in SQLite using Laravel's schema builder. But, inserting a null
value doesn't issues a data constraint error, thus allowing the null value being inserted.
As seen in the docs for SQLite3, to define a working NOT NULL
data constraint we need to append a conflict cause, otherwise it will not do anything.
I was looking through the source of Illuminate\Database\Schema\Blueprint
and Illuminate\Database\Schema\Builder
and cannot see a way of adding that on-conflict
clause. I'm wondering if it is not possible to have a method that could allow appending raw string for a column. I believe it could defeat the purpose of being database agnostic, that's why I'm creating this issue here.
To reproduce the explained issue run the following code (using a SQLite database):
Schema::drop('test');
Schema::create('test', function($table)
{
$table->increments('id')->unique();
$table->string('password', 64);
});
DB::table('test')->insert([
'password' => null,
]);
var_dump(DB::table('test')->get());
The desired SQL would look as follow for adding the aforementioned on-conflict
clause:
CREATE TABLE TEST (
ID INTEGER PRIMARY KEY,
PASSWORD VARCHAR NOT NULL ON CONFLICT FAIL);