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 exceptions #75

Closed
mrshll1001 opened this issue Mar 18, 2014 · 48 comments
Closed

No such table exceptions #75

mrshll1001 opened this issue Mar 18, 2014 · 48 comments

Comments

@mrshll1001
Copy link

Even though I've explicitly called the .save() method on my subclass of SugarRecord (Exercise) when the database is created I'm getting errors when querying and there's no such table exceptions associated with the class.

@raghunathj
Copy link

Try to increment your database version in the manifest file. That might work.

@marklapasa
Copy link

I am getting this issue too

@satyan
Copy link
Collaborator

satyan commented Apr 11, 2014

Can you check with your configuration if they're fine.

Another thing is:

With 1.2 you need to have a constructor with Context parameter.
with 1.3 beta, you need a default constructor (no parameter constructor).

If it still doesn't work, please post your configuration and one of your entity classes. thanks.

@marklapasa
Copy link

Hi Satyan,

I am using 1.3 beta now. I can see how SugarDb.getDomainClass(String, Context) was failing to get any children of SugarRecord. It's not well documented that devs need to create empty constructors in their classes that extend from SugarRecord. The readme or the main website documentation should be updated. v 1.2 was such a joy to use but going v1.3 was very frustrating.

This line is the culprit:

return (T) discoveredClass.getDeclaredConstructor().newInstance();

It fails to create an instance of a class that extends from SugarRecord if that class should have at least one constructor that has 1 or more parameters. It would be ideal that we didn't have to define boilerplate empty constructors but I'm not quite sure if it's possible v 1.3 and onward.

The reason why is I think most of us define our Entities with convenience constructors like:

public Book(String field0, String field2){...}

As soon as we create a constructor like this, the default empty one is not automatically created. Also, there is no guarantee a developer will create only one constructor as he/she could create many.

Wishful thinking would be to invoke the superclass's constructor (SugarRecord's) when the problem line is run but that doesn't work as I've experimented.

@988uhuj
Copy link

988uhuj commented Jul 12, 2014

I think this is necessary.

<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="com.example" />

Specify a package name where your domain/entity classes are present. This helps in smoother table creation.

@skunkwerk
Copy link

I'm having the same issue.
I'm on 1.4 beta, with the following entity class:

public class Router extends SugarRecord
{
String ssid = null;
String mac_address = null;

public Router() {}

public Router(String ssid, String mac_address)
{
    super();
    this.ssid = ssid;
    this.mac_address = mac_address;
}

}

this is my AndroidManifest.xml:

<application android:icon="@drawable/ic_launcher_original" android:label="@string/app_name" android:name="com.orm.SugarApp">

<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="com.app.model" />
<meta-data android:name="QUERY_LOG" android:value="true" />
<meta-data android:name="DATABASE" android:value="test.db" />
<meta-data android:name="VERSION" android:value="1" />

Any ideas?

thanks,
imran

@whoshuu
Copy link
Collaborator

whoshuu commented Jul 18, 2014

Hey @skunkwerk, I tried your code and it works just fine. Are you certain that your Router class is explicitly defined in the package, com.app.model?

Also, if you've previously created a database with that class in another form (different class name or different set of member fields), then you'll have to do an explicit migration to alter the database table, or delete the database table and let Sugar ORM create another one for you. Let me know if you need help with any of these things.

@stephanepechard
Copy link

I have the same error on my device (Nexus 5), either on allList():

E/AndroidRuntime( 5460): java.lang.RuntimeException: Unable to start activity ComponentInfo{fr.s13d.photobackup/fr.s13d.photobackup.PBJournalActivity}: android.database.sqlite.SQLiteException: no such table: PB_PICTURE (code 1): , while compiling: SELECT * FROM PB_PICTURE

or on save():

E/SQLiteLog(14252): (1) no such table: PB_PICTURE
E/SQLiteDatabase(14252): Error inserting DATE=1418849113896 FILE=/storage/emulated/0/DCIM/Camera/IMG_20141217_214512.jpg UPLOADED=false
E/SQLiteDatabase(14252): android.database.sqlite.SQLiteException: no such table: PB_PICTURE (code 1): , while compiling: INSERT INTO PB_PICTURE(DATE,FILE,UPLOADED) VALUES (?,?,?)

but the weird thing is that it does not occur on the emulator... An idea what I could do to fix this?
Thanks

@stephanepechard
Copy link

Ok, after having deleted application data, it works well.
It's curious, because I tried to uninstall the app, with success...
Thanks for reading me anyway :-)

@idemax
Copy link

idemax commented Jan 19, 2015

Create a empty constructor if you created one with arguments. Works to me after I cleared cache of app.

@exadeci
Copy link

exadeci commented Jan 21, 2015

I tried it all still the same error -_-

@idemax
Copy link

idemax commented Jan 21, 2015

What error @exadeci ? And please paste you class too.

@exadeci
Copy link

exadeci commented Jan 22, 2015

@idemax The error was "No such table" but I created a new package for my models and it worked :)

@carlochess
Copy link

incrementing my database version in the manifest file work for me, also making a public constructor with no parameters.

@TekYin
Copy link

TekYin commented Feb 23, 2015

I got the same problem. I already following the "getting started" guide.. after searching for answer, I figured it by putting my package name of my classes of SugarRecord on "DOMAIN_PACKAGE_NAME"

@danksky
Copy link

danksky commented Mar 14, 2015

Please show what creating the constructor would look like

@whoshuu
Copy link
Collaborator

whoshuu commented Apr 1, 2015

I believe many of these issues are a result of outdated documentation. When 1.4.0 is released, I'll be sure to update http://satyan.github.io/sugar to be as up to date and thorough as possible.

@OmarMahdoui
Copy link

I was having this error and i uninstalled my application and cleared cache and everything worked well .
I'm using 1.4.0 beta

@blackvvine
Copy link

the "no such table" error was solved for me when I correctly set the "DOMAIN_PACKAGE_NAME" meta data in AndroidManifest.xml
I simply used the exact package name of the database record classes.

@voghDev
Copy link

voghDev commented Jul 9, 2015

I had the same issue on Sugar v1.3.
Fixed it by leaving a default constructor without parameters for my class extending SugarRecord.

[...]
Exact error was: Error inserting .... android.database.sqlite.SQLiteException: no such table: SERIALNUMBER (code 1): , while compiling: INSERT INTO [...]

@don-han
Copy link

don-han commented Aug 18, 2015

If you are using findWithQuery and are manually entering a table name, you may get the exception that the table does not exist since your table name in Java class and your table in SQLite may differ.

For example, if you have a table called "ExampleTable", SQLite will create "EXAMPLE_TABLE". To address this, use StringUtil.toSQLName("TableName"). Of course, the best way would be to use other methods in which you don't have to manually input the table names as detailed here

@fanadd
Copy link

fanadd commented Oct 30, 2015

Does it make sence to throw an exception if SugarRecord<> successor doesn't have a default constructor?

@blackvvine
Copy link

@fanadd I believe it does since SugarORM tries to instantiate it using reflection. It's not a code generator ORM.

@damianon
Copy link

I still have this error (non such table) with 1.4 and the documentation is still very much outdated. tried all of the above (version number, domain package name, clearing cache/deleting app) nothing worked

@voghDev
Copy link

voghDev commented Nov 16, 2015

@dnano91 tried the empty constructor thing? see my comment above

@damianon
Copy link

Yes, had an empty constructor anyway. That's why I forgot to mention it
Am 16.11.2015 12:55 schrieb "Olmo Gallegos" notifications@github.com:

@dnano91 https://github.com/dnano91 tried the empty constructor thing?
see my comment above


Reply to this email directly or view it on GitHub
#75 (comment).

@martijndebruijn
Copy link

I had the same error. It was caused by a wrong definition of the package name in the manifest file. I configured the root package of the app and not the package containing the model classes.

@moyheen
Copy link

moyheen commented Mar 15, 2016

I had the same error. I was using findWithQuery and manually entering a table name. I had to change my table name from ExampleTable to example_Table before the query worked.

@VKiril
Copy link

VKiril commented Mar 16, 2016

@moyheen try to change database version from n to n+1 (for ex.)

@martijndebruijn
Copy link

When using Android Studio with Instant Run see issue #542

@firaskafri
Copy link
Contributor

Instant Run now works #564

@shashi2459
Copy link

I am getting same exception on my MotoG3- Marshmallow.
But same code runs on Kitkat tablet.
I m using 1.4 version.
What will be the specific reason on Marshmallow?

@JonatanSalas
Copy link
Collaborator

@shashi2459 if you use Android Studio it's because InstantRun generates own .dex files that Sugar don't take care, so when trying to deploy the app using InstantRun you don't get the tables generated.

@shashi2459
Copy link

Yes im using Android Studio....But the same code runs on Kitkat tablet with and without INSTANT RUN

@sibelius
Copy link
Contributor

sibelius commented Apr 6, 2016

Sugar takes care when Android Studio uses InstantRun, this pull #564 fix this

@JonatanSalas
Copy link
Collaborator

@sibeliusseraphini I refer to Sugar v1.5 not to the master branch.

@shashi2459
Copy link

@sibeliusseraphini I already tried v1.5 and the issue continues.

@JonatanSalas
Copy link
Collaborator

@shashi2459 the PR is in the master branch. Just configure your project to use the master and it will work.

@shashi2459
Copy link

@sibeliusseraphini how and where to configure it for Android Studio and Gradle?
Thanks.

@sibelius
Copy link
Contributor

sibelius commented Apr 6, 2016

@shashi2459 there is some instructions of using the master version with your project on README

@MatthewCochrane
Copy link

Had the same problem - turned out to be a problem with instant-run.
Didn't want to switch to master (using 1.5) so just disabled instant run.

To disable Instant Run:
Open the Settings or Preferences dialog.
Navigate to Build, Execution, Deployment > Instant Run.
Uncheck the box next to Enable Instant Run.

@uzbit
Copy link

uzbit commented Apr 13, 2016

The suggestion of changing ExampleTable to example_Table in a findWithQuery suggested by @moyheen worked for me. This is not terribly encouraging since it was working with EXAMPLE_TABLE before I upgraded Android Studio to 2.0 and SDK to 23.0.3, Sugar ORM from 1.3 to (tried 1.4 and now on 1.5, both of which didn't work with the old table names).

@martijndebruijn
Copy link

I switch InstantRun off when I know Sugar has to create/modify tables. After the table DDL actions you can enable InstantRun again.

@truefedex
Copy link

Please, add instant run patches to release version - on new Android studio any demos not working without it.

@sibelius
Copy link
Contributor

@truefedex you can use master version, just follow readme instructions

@augustosalazar
Copy link

Hi, it is not working for me using "com.github.satyan:sugar:1.4".

@augustosalazar
Copy link

Not working using compile 'com.github.satyan:sugar:1.4'

public class Data extends SugarRecord {

String data1;
String data2;

public Data() {
}

public Data(String data1, String data2) {
    super();
    this.data1 = data1;
    this.data2 = data2;
}

@fomojola
Copy link

If you're using 1.5, I've found that I have to give the library a bit of a kick to get it started. If you do

adb logcat -s Sugar:*

and you don't see something like this:

I/Sugar   (12467): domain class : Event
I/Sugar   (12467): Create table if not exists 
D/Sugar   (12467): Fetching properties
I/Sugar   (12467): Creating table EVENT

Then try modifying your onCreate() in your App to look like this:

public void onCreate()
    {
        super.onCreate();

        // cheating: this forces Sugar to create or upgrade the DB
        new SugarDb(this).getDB().close();
    }

Suboptimal, but I found that this forces the database tables to be created (once you are sure you have all the required constructors/annotations setup right).

One potential improvement to the logging would be logging verification failures: i.e. whenever the ReflectionUtil retrieves a class that SHOULD be a candidate but fails it because it is missing an annotation or a required constructor make that an explicit log statement.

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

No branches or pull requests