SugarORM not creating tables / column not found

Chai Jia Xun
a read

I have not posted in quite a while, but I've been quite busy working on a few cool projects. I'll be posting about those in the coming months, after my exams.

In the meantime, I feel compelled to address a problem that I have spent countless (not really, I actually counted) hours poring over.

I've been coding an Android app that used SugarORM. It's a very nice ORM for Android and I see no reason not to use it. Except that it didn't work. Except when it did. It was a very confusing and frustrating time.

Symptoms

I've been having problems where Sugar simply does not create the tables and I get an error message about tables not being created.

FATAL EXCEPTION: main
Process: com.chaijiaxun.pm25tracker, PID: 21680
android.database.sqlite.SQLiteException: no such table: SENSOR_READING (code 1): , while compiling: SELECT * FROM SENSOR_READING

When it finally does work, and I needed to migrate the database, it kept telling me the new fields I entered did not exist. Almost as if SugarORM was not creating the new database.

Searching for my problem provided many solutions. One of which was to increase my database version number to assist in migrations. This did not work.

Solution

Settings screen to turn off instant run

tl;dr

SugarORM is not compatible with Android Studio's Instant Run. Turn it off.

For those interested, I'm using Sugar v1.4 and Android Studio 2.3

compile 'com.github.satyan:sugar:1.4'
Android Studio 2.3
Build #AI-162.3764568, built on February 24, 2017
JRE: 1.8.0_112-release-b06 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

I do hope this solves someone's problems. I can't be the only one using SugarORM with Instant Run can I?

Check the next post: Design of Google Cardboard ยป

Share on:
Chai Jia Xun
Chai Jia Xun

Jia Xun speaks of himself in the third person when writing his bio. He thinks he's being cute but we all know that's just cliche. Being meta is so passe. Why do people still do it?