google-developer-training / basic-android-kotlin-compose-training-inventory-app

Apache License 2.0
77 stars 84 forks source link

Persist data with Room #6

Closed wngu6 closed 1 year ago

wngu6 commented 1 year ago

URL of codelab:

Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found?

  1. Create an item Entity, Data Classes: Step 2

Describe the problem The tableName in @Entity(tableName = "items") should be @Entity(tableName = "item"), otherwise the following error will occur during build:

There is a problem with the query: [SQLITE_ERROR] SQL error or missing database (no such table: item)

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions Android Studio version: API version of the emulator:

Additional information Include screenshots if they would be useful in clarifying the problem.

PICO443 commented 1 year ago

The tableName should be "Item" not "Items" following the note from the previous codelab:

Note: Like with Kotlin classes, the convention is to use the singular form for the name of database tables. For the example above, that means you name the tables teacher, student, and course, not the plural forms of teachers, students, and courses.

lyay commented 1 year ago

Note: Like with Kotlin classes, the convention is to use the singular form for the name of database tables.

Тогда переименуйте таблицу в 5. Create an item Entity !

Сейчас так: @Entity(tableName = "items") data class Item( ... )

Странно, конечно, использовать единственное число для сущности, содержащей много предметов. Раз уж приняли правило, так применяйте везде. В текущем виде пример не работоспособен.

fe60 commented 1 year ago

Course containing the note about table naming convention mentioned by @PICO443 above. https://developer.android.com/codelabs/basic-android-kotlin-compose-sql#1

Inconsistent naming of database tables can be found in Android Room guide too. For the definition of entities it uses a plural word for table name, while the example shows singular naming in a query for accessing the data.

osuleymanova commented 1 year ago

Hello @wngu6,

Thank you for reaching out to us. It is fixed and published.