Reputation: 187
Version 11.4
All of my Sqlite table fields are set to NOT NULL.
I have tried the following in the table creation command ..
t.column(miny, defaultValue: nil)
but the fields are still all defined 'NOT NULL'
How do I set a field to accept a NULL value?
Upvotes: 0
Views: 298
Reputation: 187
Doh! - found the answer looking through the testing scripts in github - then noticed the comment in the docs.
Need to make the types optional using a '?' - as with the last 4 Double fields in this example ..
let title = Expression<String>("title")
let descr = Expression<String>("descr")
let miny = Expression<Double?>("miny")
let minx = Expression<Double?>("minx")
let maxy = Expression<Double?>("maxy")
let maxx = Expression<Double?>("maxx")
Upvotes: 1
Reputation: 521429
Have you tried the following syntax:
t.column(miny)
From the SQLite documentation:
The default value of each column is NULL
So you should not have to specify anything extra in a column definition in order for it to be nullable, because the default value is already null.
Upvotes: 0