sugar: No such table !!

hi i tried a lot to make sugar database work but it keeps returning NO SUCH TABLE error here is my code:

manifest: `<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="he.hrm.test48">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <meta-data android:name="DATABASE" android:value="shd.db" />
    <meta-data android:name="VERSION" android:value="1" />
    <meta-data android:name="QUERY_LOG" android:value="true" />
    <meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="he.hrm.test48" />
</application>

</manifest>`

book class:

`public class Book extends SugarRecord { @Unique String isbn; String title; String edition;

// Default constructor is necessary for SugarRecord
public Book() {

}

public Book(String isbn, String title, String edition) {
    this.isbn = isbn;
    this.title = title;
    this.edition = edition;
}

}`

MainActivity

`public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    SugarContext.init(getApplicationContext());
}

public void gogo(View view){
    Book book = new Book("bbeb","cecf","tegdt");
    book.save();
}

}`

it doesn’t work at all and the exception is “no such table: BOOK (code 1): , while compiling: INSERT OR REPLACE INTO BOOK(TITLE,ISBN,ID,EDITION) VALUES (?,?,?,?)”

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 6
  • Comments: 34

Most upvoted comments

<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="he.hrm.test48" />

This the package where you define your models for example if you define your models in he.hrm.test48.models/Book.java than “he.hrm.test48.models” should be your DOMAIN_PACKAGE_NAME

Clearly.

  1. Check that your class child of Application extends from SugarApp or has inside the following lines SugarContext.init(this); not use getApplicationContext() instead this

  2. Check that your Instant Run is disabled.

3 Check that your DOMAIN_PACKAGE_NAME set is correctly.

  1. Check that after changes (add lines on Application or disabling Instant Run) you remove app from your phone or clear app data.

  2. Check that version of your bd >= 2 (as stated on the website of the author)

  3. Trying Build->Clean Project->Rebuild Project after changes. It’s helped for me

I had the problem, updating everything and restarting android studio helps. It suddenly started working for me, I can’t explain why exactly it didn’t work before.

Clear the app data & cache or clean install the app

The problem is DOMAIN_PACKAGE_NAME you need to point it to where your models are being kept Quick question , where is your book class? <meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="he.hrm.test48" /> you sure you placed it inside /he/hrm/test48?

And after you disable instant run, make sure you uninstall the app from the phone/emulator before running again.

Here I have some experiences with Sugar ORM library:

  1. My application has own DatabaseHelper class and I want to integrate Sugar ORM for some new module with same database.But I facing same issue of “no such table” error and I couldn’t get any solution still now.
  2. And one good thing is that my another two applications which are totally based on Sugar ORM, are working very well without any issue. I could not understand what happens in first case.