Search code examples
iosgrdb

What to do to make an existing non-optional field optional in database table in SQlite?


I am using GRDB for local persistence.

Created a column in the Item table with the following constraints.

table.column(Item.CodingKeys.text.rawValue, .text).notNull()

Now I want to change it to support optional values as well.

table.column(Item.CodingKeys.text.rawValue, .text)

But in order to migrate, I cant alter its property. Only add, rename available for the column.

What approach should I take to properly migrate while keeping backward compatibility?


Solution

  • ALTER COLUMN is not possible in SQLite.

    Only Supported alter operations:

    • Alter Table Name
    • Alter Table Column Name
    • Add New Column
    • Drop Column

    Reference: