What is the best way to change an existing table with SQLite (add new columns) without losing the table data?
Asked
Active
Viewed 70 times
1 Answers
0
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.

Mozahler
- 4,958
- 6
- 36
- 56