Change existing table with SQLite.swift?

151 Views Asked by At

What is the best way to change an existing table with SQLite (add new columns) without losing the table data?

1

There are 1 best solutions below

0
On

Any time you change a table you have to consider the existing dataset. The data in your DB was created with your old/original table definition and doesn't know anything about the new one. So the data needs to be migrated.

When you migrate a DB, you tell it how to massage the existing data to conform to the new definitions. This often involves inserting a default value, but this isn't a requirement.

There is an excellent (open source) tool that can help you with this process called SQLiteMigrationManager, and it can be found here:

SQLiteMigrationManager.swift (inspired by FMDBMigrationManager)

If you run into any problem be sure to open a new question on this site and I'm sure you will be assisted.