android.database.sqlite.SQLiteException: table X has no column named Y: , while compiling: INSERT INTO

后端 未结 9 796
心在旅途
心在旅途 2020-12-11 05:52

this is my error in console :

11-29 19:06:50.295: E/AndroidRuntime(333): android.database.sqlite.SQLiteException: table usuarios has no column named email: ,         


        
相关标签:
9条回答
  • 2020-12-11 06:11

    This problem occurs mostly when you make a change in the database but do not delete the previous database. Uninstall the app and then run it.

    0 讨论(0)
  • 2020-12-11 06:13

    Uninstall the app, and again install it, because it can be solve by using two approaches, one by using

    alter method and increment version

    or

    creating the table again by reinstalling the app

    0 讨论(0)
  • 2020-12-11 06:18

    This problem is mainly caused by syntax. for example, previously my code was correct. here it is:

        String CREATE_PRODUCTS_TABLE = "CREATE TABLE " + TABLE_PRODUCTS + "("
                        + COLUMN_ID + " INTEGER PRIMARY KEY," + COLUMN_MESSAGEADDRESS
                        + " TEXT," + COLUMN_MESSAGEBODY + " TEXT " + ")";
    

    The above code was running correct but i added another column and it started causing the mentioned error. below is the erroneous code:

        String CREATE_PRODUCTS_TABLE = "CREATE TABLE " + TABLE_PRODUCTS + "("
                        + COLUMN_ID + " INTEGER PRIMARY KEY," + COLUMN_MESSAGEADDRESS
                        + " TEXT," + COLUMN_MESSAGEBODY + " TEXT" + COLUMN_MESSAGETIME + " LONG" + ")";
    

    As you can see, when i added the new column i forgot to include a comma after type TEXT. this means that when this code is executed, there will be syntax error as the compiler will read the last part as:

        COLUMN_MESSAGEBODY TEXTCOLUMN_MESSAGETIME LONG
    

    as opposed to:

        COLUMN_MESSAGEBODY TEXT, COLUMN_MESSAGETIME LONG
    

    Solution: ensure that your syntax is correct and you heed to spaces and commas.

    kindly check the below link for more info: Android : Table has no column named "variable name" MySql Database error

    0 讨论(0)
提交回复
热议问题