Unable to find table but not always

Sometimes when I run my application I get the error: No such table "tablename". Then my database gets empty and the app crash.

I am 100% sure that the table exists. The weird thing is that it doesn't happen often, about 1/30 so is hard to debug. I don't use any code to delete the table.

This is how I open the database:

- (id)initWithDB:(NSString*)dbName{
    if(self = [super init])
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:dbName];

        if (sqlite3_open([writableDBPath UTF8String], &_database) != SQLITE_OK) {
            NSLog(@"could not prepare statement: %s\n", sqlite3_errmsg(_database));
            NSLog(@"Failed to open database!");
        else {
        //WAL mode on to write and read database at the same time
        sqlite3_exec(_database, "PRAGMA journal_mode=WAL;", 0, 0, 0);

    return self;