Why is it necessary for database table id to be renamed to _id?
I created a new table in SQLite, and named one of the columns as id
.
When I access that database at runtime, it generates an error. I 开发者_如何学Pythonfound that in my database, I have to use _id
instead of id
. Why is it necessary for this column to be named as _id
?
It's always a good idea to declare your primary key as:
_id INTEGER PRIMARY KEY AUTOINCREMENT
That way, Android's functions, which could use the _id
to make certain things work for example the id's in a CursorAdapter
.
For the primary key of the database you should always use the identifier "_id" as some of Android functions rely on this standard.
From this source (direct quote)
精彩评论