DBFlow icon indicating copy to clipboard operation
DBFlow copied to clipboard

Should I clear the DBflow instance after removing the database?

Open darkovski88 opened this issue 11 years ago • 5 comments

Im removing the database in my app, so I can re-init the app. But after deleting, while adding the data im getting duplicate primary keys conflict - its like the data is still there(in cache or something like that)?

This works fine if reopen the app and load the data again, like there is something that resets DBFlow.

Can someone help me how can I propperly clear the data so I can start inserting again - without closing my app first?

Here is what im doing while deleting the DB:

        getDatabasePath(BetterBillDatabase.NAME).delete();
        FlowManager.getDatabase(BetterBillDatabase.NAME).reset(this);
        FlowManager.init(this);

darkovski88 avatar Sep 08 '15 11:09 darkovski88

I had the same issue and I ended up deleting table by table:

private void deleteAllTables() {
        deleteAllLogTables();
        deleteAllDownloadedTables();
    }

    private void deleteAllDownloadedTables() {
        Delete.tables(tableListExtendingFromModel);
    }

    private void deleteAllLogTables() {
        Delete.tables(AccreditationLog.class, AdmissionLog.class);
    }

Not the elegant way but works whithout applying reflection: https://github.com/Raizlabs/DBFlow/pull/253

arturonaredo avatar Sep 27 '15 20:09 arturonaredo

I'm facing this issue right now. Is there a proper fix / work-around for this ?

Thanks!

nsatvik avatar Oct 03 '15 11:10 nsatvik

Same problem here. @agrosner Have you any idea?

Alireza-Farahani avatar Oct 04 '15 12:10 Alireza-Farahani

Since I opened this issue, I fogot to say that I found the answer few days ago. The answer is this:

// Delete a whole table Delete.table(MyTable.class, conditions); // Delete multiple instantly Delete.tables(MyTable1.class, MyTable2.class);

You can see more here: https://github.com/Raizlabs/DBFlow/blob/master/usage/SQLQuery.md

darkovski88 avatar Oct 04 '15 12:10 darkovski88

I've been using that reflection hack in production for months now, no issues. This is still an issue DBFlow should be solving though, not its users.

On Sun, Oct 4, 2015, 8:26 AM khafan [email protected] wrote:

Same problem here. @agrosner https://github.com/agrosner Have you any idea?

— Reply to this email directly or view it on GitHub https://github.com/Raizlabs/DBFlow/issues/390#issuecomment-145344278.

kaeawc avatar Oct 04 '15 12:10 kaeawc