我为数据库添加了新的命令,在使用ReActive android数据库运行程序时遇到此错误。
无法创建应用程序com.reactiveandroid.sample.App:java.lang.IllegalArgumentException:找到SQL文件资产/from_2_to_3.sql注释。
@Database(name = "AppDatabase", version = 3)
public class AppDatabase {
static final Migration MIGRATION_1_2=new Migration(1,2) {
@Override
public void migrate(SQLiteDatabase database) {
AssetsSqlMigration.executeSqlScript(database,"assets/from_1_to_2.sql");
}
};
static final Migration MIGRATION_2_3=new Migration(2,3) {
@Override
public void migrate(SQLiteDatabase database) {
AssetsSqlMigration.executeSqlScript(database,"assets/from_2_to_3.sql");
}
};
}
公共类应用程序扩展了应用程序{
@Override
public void onCreate() {
super.onCreate();
DatabaseConfig appDatabaseConfig = new DatabaseConfig.Builder(AppDatabase.class)
.addModelClasses(Note.class, Folder.class, NoteFolderRelation.class)
.addMigrations(AppDatabase.MIGRATION_1_2 ,MIGRATION_2_3)
.disableMigrationsChecking()
.build();
ReActiveAndroid.init(new ReActiveConfig.Builder(this)
.addDatabaseConfigs(appDatabaseConfig)
.build());
}
}
ALTER TABLE注意添加列nameid INTEGER;
答案 0 :(得分:0)
您需要按照以下说明在migrate()
中编写DDL查询。
static final Migration MIGRATION_2_3 = new Migration(2, 3) {
@Override
public void migrate(SupportSQLiteDatabase database) {
// if you need to create new table
database.execSQL("ALTER TABLE your_table "
+ " ADD COLUMN column_name DATATYPE");
}
};