Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No such table error #50

Closed
amaurymuro opened this issue Oct 15, 2013 · 74 comments
Closed

No such table error #50

amaurymuro opened this issue Oct 15, 2013 · 74 comments

Comments

@amaurymuro
Copy link

Hi, I am new with Sugar. I have a simple android project with a single record named "Abonado". I have followed the wiki' steps but when I ran the project and I had the error: "android.database.sqlite.SQLiteException: no such table: ABONADO (code 1): , while compiling: SELECT * FROM ABONADO". Then I looked the db file created and it’s true, the table ABONADO does not exit.
Then I looked the master project SugarActivity and it does not make the tables either and I also had another similar error: "android.database.sqlite.SQLiteException: no such table: TEXT_NOTE (code 1): , while compiling: DELETE FROM TEXT_NOTE".
Have you experienced this issue before?Could you please help me? Thanks in advanced. Respectfully.
ohh I am using android 4.2

@satyan
Copy link
Collaborator

satyan commented Oct 15, 2013

Can you share your model class and the android manifest.. Must be a configuration issue.

thanks,
Satya

@amaurymuro
Copy link
Author

This is my manifest:

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:name="com.orm.SugarApp"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.empresaelectrica.MainActivity"
        android:label="Empresa Eléctrica II" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.empresaelectrica.AddAbonado"
        android:label="@string/title_activity_add_abonado"
        android:parentActivityName="com.example.empresaelectrica.MainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.empresaelectrica.MainActivity" />
    </activity>

    <meta-data
        android:name="DATABASE"
        android:value="abonados.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="com.example" />
</application>

@amaurymuro
Copy link
Author

2013-10-15-135029_1440x900_scrot

@lesiki
Copy link
Contributor

lesiki commented Nov 22, 2013

Hi @amaurymuro. I got the same thing, and like you I had included all 4 optional meta-data tags in my manifest. Removing them fixed it for me (and I don't mind having default db name).

@satyan probably one of these that causes the issue? If it helps, my meta-data config was:

    <meta-data android:name="DATABASE" android:value="myapp.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="com.me.myapp.model" />

@awidarto
Copy link

awidarto commented Jan 5, 2014

Happened to me too, but turn out that what was wrong was me not following the Getting Started doc.
I changed the VERSION metadata value to 1, because logically I thought I will be creating the first version of the db at installation, but I was wrong, I guess it was supposed to be used in migration process, so I changed back the value to 2 ( as suggested in the doc ), and it just works.

@satyan , maybe more verbose documentation is necessary here, i.e. in that description of VERSION metadata, just to keep people changing that default value of 2 to 1 initially. Thanks !

@YaariBoaz
Copy link

guys,
i'm having the same problem...any fixes?

@lesiki
Copy link
Contributor

lesiki commented Jan 30, 2014

@DidiPc if it's an option for you, try what I did - drop the meta-data tags. One of them is the cause. @awidarto's comment above makes it sound like the problem is the version metadata, so you could start with that.

@satyan
Copy link
Collaborator

satyan commented Jan 30, 2014

@DidiPc can you share your manifest and the entity class. Also, try removing the app from the device and running afresh.

If, for some reason, there's an issue with creating table, it would throw this error while performing any db operations.

@ciotto
Copy link

ciotto commented Feb 26, 2014

Hi, I'm had the same problem and I'm resolved by implementing the empty constructor in my SugarRecord subclass.

@ggauravr
Copy link

@ciotto Right. Just checked with my old code, and the only difference was the absence of empty constructor. It's fixed after adding that !

@satyan
Copy link
Collaborator

satyan commented Apr 11, 2014

As of 1.2 build, we had a requirement of having a constructor with Context paramter.
With 1.3 beta, we removed that constraint. But we still need the default constructor (i.e.) an empty constructor. In absence of which, the tables fail to get created..

@whoshuu
Copy link
Collaborator

whoshuu commented Jul 4, 2014

This issue has been resolved. Closing it.

@whoshuu whoshuu closed this as completed Jul 4, 2014
@rdenadai
Copy link

Just to complement anyone how fall on this page, im using Sugar ORM on version 1.3 ... had the same error, removing thie package tag DOMAIN_PACKAGE_NAME solved for me... im still using the other 3.

@bbody
Copy link

bbody commented Aug 18, 2014

I am also having a similar problem. If I don't have DOMAIN_PACKAGE_NAME, I get a NullPointerException on my main Activity, if I do have it declared I get the no table error. I have tried with and without the optional attributes but still get those errors. I also have the blank constructor in my model.
(I am using version 1.3)

@rdenadai
Copy link

@bbody how are you import the lib? Using gradle?
In my test im not using gradle, im using eclipse latest with adt latest also! (im not using bundle because bundle has a problem with annotations).

@bbody
Copy link

bbody commented Aug 24, 2014

I am using Gradle. I am exploring other libraries at the moment.

@rdenadai
Copy link

@bbody since im not using gradle, cant say that could be a issue to that... don't think so but.
Assure that your classes have an empty constructor as the guys said above.

@bbody
Copy link

bbody commented Aug 28, 2014

I have followed all the aforementioned solutions to no avail.

@rdenadai
Copy link

@bbody could you share yours package tags used on android manifest? And one of your classes that extend SugarRecord?
I'm also realized that my android:name="VERSION" android:value="1" isn't 1 (one)!!! Is 2 (two) ... putting 2 on this tag solve another issue i was having...
This must be done even if i install the app from zero!

@ECriew1928
Copy link

@bbody i also tried everything suggested without success, in the end i deleted the applications cache and now it works

@AhmedNMahran
Copy link

I tried above solutions but failed
Finally,Thanks to Allah, i decided to change my class name (it was Mobile, changed to phone) and made version =1 and worked!

@worker8
Copy link

worker8 commented Nov 10, 2014

I'm facing this problem too and the version used is 1.3. I managed to solved it by removing the Constructor of the model class completely, hope it helps someone with similar issue!

@nesasivan
Copy link

where we need to use the constructor

@Raguking
Copy link

where we need to use the constructor??

@mouhsinelonly
Copy link

this should really be fixed +1

@divyanshunegi
Copy link

Why is this library so buggy ? Satyan please write some more documentation in the website, in example you have created class without context and in another database creation method there you are passing context, please fix these little issues. BTW , it crashes in my device and also shows a white screen when app starts for 100- 200 ms.

@ksrpraneeth
Copy link

I was having the same issue i solved it by adding

  1. public empty constructor (Public constructor is must.)
  2. Increasing the VERSION in manifest file to '20'(can be anything)

@HosseinKurd
Copy link

Is it possible to Add new table in new version released without removing older version ??

@fbngrm
Copy link

fbngrm commented Jul 27, 2015

Solved by changing the database name:
<meta-data android:name="DATABASE" android:value="ae_qt_01.db" />
to:
<meta-data android:name="DATABASE" android:value="ae01.db" />

@sibelius
Copy link
Contributor

sibelius commented Dec 2, 2015

do you have a drawable ic_launcher?

@ontur00
Copy link

ontur00 commented Dec 3, 2015

I try at new TestProject.
I add
compile 'com.github.satyan:sugar:1.4' - sync project - to gradle
new class at package where is my activity (com.example.user.testsugar1_4 )
in my main activity Book book = new Book("isbn123", "Title here", "2nd edition");
Book.save(); and :

Exception :
Caused by: java.lang.NullPointerException: SugarContext has not been initialized properly. Call SugarContext.init(Context) in your Application.onCreate() method and SugarContext.terminate() in your Application.onTerminate() method.

I use this tutoriall - https://android-arsenal.com/details/1/337

http://pastebin.com/iB1J1KRj - main activity
http://pastebin.com/dgdy7eiX - manifest
http://pastebin.com/jESs2KjQ - gradle

@sibelius
Copy link
Contributor

sibelius commented Dec 3, 2015

public class TestProjectApp extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        SugarContext.init(this);
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        SugarContext.terminate();
    }

}

@ontur00
Copy link

ontur00 commented Dec 3, 2015

First Thank you very much for help @sibeliusseraphini

I fixed I use a 1.3, I had a mistake in the manifest

meta-data android: name = "DOMAIN_PACKAGE_NAME" android: value = "com.example.user.wrongPackage.Model" - wrong PACKAGE

Advice to other check if you have a well-configured manifest

@RodryVazquez
Copy link

I just to have the same problem, I fixed by adding an empty contructor, and compile with the 1.3 Sugar orm version and rainstalled the app, and before new testing run cleanner in device and clear cache.
my ManifestFile looks like :

meta-data android:name="DATABASE" android:value="MyDb.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="com.example.DemoApp.Models"

Models content a Sugar model classes for example => example extends SugarRecord

@krazykira
Copy link

For me this error occured because i had Multidex enabled and i was using a lot of libraries around 20 of them and it was a very big project with a lot of classes. I debugged and went through the source code and i confirmed it there that the classes that extended sugar record were never found so in the end i added my classes explicitly into the source code in order to get my project to work.

I don't know if this would help other but it certainly something that the devs should look into. Try adding the project as library project and try debugging the source code and you will find the same issue.

@miladna7
Copy link

miladna7 commented Feb 7, 2016

i did this thing:
change DOMAIN_PACKAGE_NAME = not working
change VERSION = not working
change DATABASE = working
so i think change the db name may help u in this case.

@Gujarats
Copy link

Yes I was having the same issue, @miladna7 Thanks man your suggestion works.
But I wonder why it can't use the same database?

@sibelius
Copy link
Contributor

it is fixed on master and on 1.5 version

@aubertdavy
Copy link

Hi, no changment, i've got the same error..

@Gujarats
Copy link

@aubertdavy try to change the name of your database or update to the version 1.5

@aubertdavy
Copy link

@Gujarats yes that's what i did !!
I upgrated to 1.5, removed my app, changed my db name .. and no changment

@aubertdavy
Copy link

Ok i solved my problem extending SugarApp and passing application context (and not base context) on create overriding method

@cdaringe
Copy link

@aubertdavy, can you be more specific?

@aubertdavy
Copy link

@cdaringe
Init SugarContext in a derived Application class, passing application base context solved my problem.

@aubertdavy
Copy link

public class MySugarApp extends Application {
@OverRide
public void onCreate() {
super.onCreate();
SugarContext.init(getApplicationContext());
}
}

@cdaringe
Copy link

i'm sorry to be a total rookie on this (i rarely code java), but no where in my current app do I use Application explicitly (perhaps implicitly?). Even if so, I'd like to write some unit tests--I'm unsure how'd I'd get the context otherwise if there'd be no Context in the test suite.

thanks for the tip.

@cdaringe
Copy link

nm, @aubertdavy, i did figure out how to do that. still gives the error, though, unforunately

Caused by: android.database.sqlite.SQLiteException: no such table: CUSTOMER (code 1): , while compiling: INSERT OR REPLACE INTO CUSTOMER(EMAIL,ID,NAME) VALUES (?,?,?)

@RodryVazquez
Copy link

try, reinstall the app in the phone, in some cases its necesary, I never use application context to initialize sugar context in my apps

@Aiuspaktyn
Copy link

Same problem, fixed using gradle 1.5.0 (before was 2.0.0-beta7)

@firaskafri
Copy link
Contributor

Instant Run now works #564

@truongvnse03130
Copy link

i have the same problem, but i fixed by:

  • Write a subclass extends Application like this:

public class SugarORMApplication extends Application {
@OverRide
public void onCreate() {
super.onCreate();
SugarContext.init(this);
}
@OverRide
public void onTerminate() {
super.onTerminate();
SugarContext.terminate();
}
}

  • Add android:name="com.....SugarORMApplication" (to class above) in Manifest file and is fixed

@felipebonezi
Copy link

This is not working with GRADLE 2.0.0!!!!!!!

@firaskafri
Copy link
Contributor

@felipebonezi please check #564

@RodryVazquez
Copy link

yes, disable instant Run in android studio

@amrishodiq
Copy link

I tried to disable instant run on android studio 2.1.2 but still have no luck.
But actually succeed when using gradle 1.5.0.

classpath 'com.android.tools.build:gradle:1.5.0'

on project's build.gradle.

I hope the patch will be released soon.

@bishwash-adhikari
Copy link

bishwash-adhikari commented Jan 6, 2017

This may help :
correct :
<meta-data android:name="DATABASE" android:value="cal.db" />
Error:
<meta-data android:name="DATABASE" android:value="cal_bi.db" />

@billgockeler
Copy link

updating build.gradle to 'com.github.satyan:sugar:1.5' fixed it for me

@cbedoy
Copy link

cbedoy commented Jan 29, 2018

Not working with kotlin using

'com.github.satyan:sugar:1.5'

@Lim-Jerico11
Copy link

Lim-Jerico11 commented Feb 28, 2018

I have a problem java.lang.NullPointerException: SugarContext has not been initialized properly. Call SugarContext.init(Context) in your Application.onCreate() method and SugarContext.terminate() in your Application.onTerminate() method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests