https://kotlinlang.org logo
#android
Title
# android
v

veer

06/28/2019, 7:24 AM
Hello there, we are facing a problem with ROOM DB it says the newly added column is not found, room library version is 2.1.0, the app crashes, we have handled adding of the column in the migration, the migration seems to be successfull since the user can use other parts of the app, but when the tables where a new column is added it crashes saying, Not all users are facing this problem only 10% of users are having this problem, and mainly on Samsung s9 with Android 9 facing more. This was the old table CREATE TABLE “pfile” (“id” INTEGER PRIMARY KEY NOT NULL ,“name” VARCHAR,“lname” VARCHAR,“rlhip” VARCHAR,“sex” VARCHAR,“wk” VARCHAR,“un” VARCHAR,“fun” VARCHAR,“pn” BOOL NOT NULL DEFAULT (1) ,“dd” DOUBLE,“add” DOUBLE,“ph” BLOB,“hk” BOOL,“th” VARCHAR,“fun” VARCHAR, “swk” VARCHAR) Changed to the below( data type of some columns changed and tun column is added) “CREATE TABLE pfile_new (id INTEGER PRIMARY KEY NOT NULL ,name TEXT, lname TEXT, ” + “rlhip TEXT, sex TEXT, wk TEXT, un TEXT, lun TEXT, ” + “pn INTEGER NOT NULL, ” + “dd REAL, pdd REAL, ph BLOB, hk INTEGER, th TEXT, fun TEXT, swk TEXT, tun TEXT)” This is the code in the migrate function database.execSQL(“”CREATE TABLE pfile_new (id INTEGER PRIMARY KEY NOT NULL ,name TEXT, lname TEXT, ” + “rlhip TEXT, sex TEXT, wk TEXT, un TEXT, lun TEXT, ” + “pn INTEGER NOT NULL, ” + “dd REAL, pdd REAL, ph BLOB, hk INTEGER, th TEXT, fun TEXT, swk TEXT, tun TEXT)” ) database.execSQL(“INSERT INTO pfile_new (id, name, lname, rlhip, sex, wk,un,lun,on,dd,pdd,ph,hk,th,fun,swk) ” + “SELECT id, name, name, rlhip, sex, wk,lun, pn,dd,pdd,ph,hk,theme, fun +swk ” + “FROM pfile”) database.execSQL(“UPDATE profile_new set tun = ‘$tun’“) database.execSQL(“DROP TABLE pfile”) database.execSQL(“ALTER TABLE pfile_new RENAME TO pfile”) This is the method in the DAO @Query(“SELECT * FROM pfile”) fun getData(): List<Pfile> Following is the error we see, java.lang.IllegalArgumentException column ‘tun’ does not exist. Available columns: [id, name, lname, rlhip, sex, wk, un, lun, pn, dd, pdd, photo, hk, th, fun, swk] com.example.database.dao.UserDao_Impl.getData
r

ribesg

06/28/2019, 7:25 AM
#room
c

CamilleBC

06/28/2019, 8:04 AM
Also, you should format the code parts using ` or ```
Like
this
or
Copy code
this
It makes it more readable. 🙂
👍 2
v

veer

06/28/2019, 5:57 PM
Thanks for the suggestions guys,
but is that the real problem for the crash?
c

CamilleBC

06/29/2019, 11:52 AM
@veer No, it is not. I can't really help here, as I'm not really an expert in SQL nor Room (I will have to dig a bit at some point though. Yet if you want an answer, you should: 1- Format the code properly, so that it is readable 2- Reduce as much as possible irrelevant variables/methods from the code snippets you give (it might be the case here, though) 3- Post on the relevant channel if it exists (Gael helped you here: #room), which you have done now. By doing this, the problem will be more easily understood by those who might have the answer. If you don't, they will struggle reading your post, and most will simply not take the time (thinking that if you don't care enough to make it understandable, why should they care about your problem). I was just trying to help you get an answer as fast as possible.
v

veer

07/01/2019, 2:22 AM
Thanks for the suggestions @CamilleBC, that will really help me start learning how to use Slack better 🙂