yuweiguocn / GreenDaoUpgradeHelper

To solve database upgrade of greenDao and just need one line code
1.53k stars 295 forks source link

当升级数据库的时候,原先的表增加了字段之后升级就会报错。 #32

Closed 2449983723 closed 7 years ago

2449983723 commented 7 years ago
compile 'org.greenrobot:greendao:3.2.0'
compile 'com.github.yuweiguocn:GreenDaoUpgradeHelper:v1.4.0'//数据库升级辅助

@Override
public void onUpgrade(Database db, int oldVersion, int newVersion) {
    Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables");
        // 升级、数据库迁移操作
        MigrationHelper.migrate(db, ArrayThreeBetBeanDao.class, BetBeanDao.class,
                ElevenCFBetBeanDao.class, QuickThreeBetBeanDao.class, WelfareBetBeanDao.class, ArrayFiveBetBeanDao.class, SevenStarBetBeanDao.class,
                CqsscBetBeanDao.class, HappyPokerBetBeanDao.class);
}

新增一个表可以,但是在原来的表的基础上加了一个字段就不行了 添加的字段: private String lotteryCode; 报错 android.database.sqlite.SQLiteException: no such column: T.LOTTERY_CODE (code 1): , while compiling: SELECT T."_id",T."PLAYMODE",T."PLAYTYPE",T."DAN",T."TUO",T."BETNUMBS",T."LOTTERY_CODE" FROM "ELEVEN_CFBET_BEAN" T where LOTTERY_CODE = ? 麻烦大神帮忙看看

2449983723 commented 7 years ago

已经解决,查看代码后发现MigrationHelper中使用用reflectMethod方法dropAllTables和createAllTables出现了问题,换成DaoMaster.dropAllTables(db, true);和DaoMaster.createAllTables(db, false);就没有问题了。

yuweiguocn commented 7 years ago

已解决,请更新到2.0版本,添加了监听回调。

2449983723 commented 7 years ago

好的,我试一下

2449983723 commented 7 years ago

看了一下代码,已经解决了该问题。