Paulina Szklarska
1 min readApr 3, 2019

--

Hi Vahid!

That’s the warning indicating that’s not the most efficient solution to use foreign keys without the index.

When you have foreign key (from entity A to B) and you’re changing your A entity, Room needs to make full scan of the B table to match corresponding entities.

This may take a while, so to avoid this, it’s a good practice to index reference columns in B. So if you have your B entity, you need to put index for the column with id:

@Entity(indices = {@Index(value = {"id"}, unique = true)})
public class User {
@PrimaryKey
public final int id;
public final String login;
public final String avatarUrl;
}

Hope this helps!

--

--

Paulina Szklarska
Paulina Szklarska

Written by Paulina Szklarska

Flutter GDE / Flutter & Android Developer / blogger / speaker / cat owner / travel enthusiast

Responses (1)