我正在使用FMDB IOS框架来管理我的sqlite数据库。
但是现在我有我的数据库的第二个版本,所以我需要更新我的sqlite文件(在安装了应用程序的设备上)
以下是我的步骤:(数据库在Application Support / db / db.sqlite中)
每次启动都使用此代码
-(void)migrateWithDBAtPath:(NSString *)dbPath {
FMDBMigrationManager *manager = [FMDBMigrationManager managerWithDatabaseAtPath:dbPath migrationsBundle:[NSBundle mainBundle]];
NSError *error = nil;
BOOL success = [manager migrateDatabaseToVersion:UINT64_MAX progress:nil error:&error];
}
dbPath是... / Library / Application Support / db / db.sqlite
但是在这个步骤之后,我在migrateDatabaseToVersion中没有迁移和0 pendingVersions:progress:error:
我做错了什么?感谢。
答案 0 :(得分:0)
Objective-C方式:
FMDBMigrationManager * manager = [FMDBMigrationManager managerWithDatabaseAtPath: @"Path to your db" migrationsBundle:[NSBundle mainBundle]];
//Path to the sql file with the statements to apply to your db
NSString * expectedPath = [[NSBundle mainBundle] pathForResource: @"1" ofType: @"sql"];
FMDBFileMigration * fileMigration = [FMDBFileMigration migrationWithPath: expectedPath];
//Apply the statements in 1.sql
BOOL successFileMigration =[ fileMigration migrateDatabase: [manager database] error:nil];