Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6876677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:30:26+00:00 2026-05-27T04:30:26+00:00

I constructed the following database: private static final String CREATE_TABLE_TEST= create table + TABLE_TEST

  • 0

I constructed the following database:

   private static final String CREATE_TABLE_TEST=
        " create table " + TABLE_TEST +
        " (test_id integer primary key autoincrement," +
        COL_GRADE +" text not null," +
        DATE+" text not null);";



private static final String CREATE_TABLE_QUESTION=
        " create table " + TABLE_ANSWER +
        " (question_id integer primary key autoincrement," +
        COL_ANSWER_1+ " text not null,"+ 
        COL_ANSWER_2+" text not null," +
        COL_ANSWER_3+" text not null," +
        COL_ANSWER_4+" text not null," +
        COL_ANSWER_5+ " text not null,"+ 
        COL_ANSWER_6+" text not null," +
        COL_RIGHT_ANSWER+" integer," +
        COL_WRONG_ANSWER+" integer, " +
        COL_TEST_ID+" INTEGER, " + 
        "FOREIGN KEY(" + COL_TEST_ID + ") REFERENCES " + TABLE_TEST+"(test_id));";

The error persists so far:

> 11-29 18:01:20.955: E/Database(853): Error inserting right_answer=6 wrong_answer=0 answer_5=fadsfas answer_6=gadsfdasasdfa

answer_3=fasdfasf test_id=1 answer_4=fasdfsa answer_1=fasdfasd
answer_2=fasdfas

11-29 18:01:20.955: E/Database(853): android.database.sqlite.SQLiteException: table answer has no column

named test_id: , while compiling: INSERT INTO answer(right_answer,
wrong_answer, answer_5, answer_6, answer_3, test_id, answer_4,
answer_1, answer_2) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?);

@Override
public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        Log.d("database", CREATE_TABLE_TEST); //I never see this statement in catlog
        Log.d("database", CREATE_TABLE_QUESTION); //nor this
        db.execSQL(CREATE_TABLE_QUESTION);
        db.execSQL(CREATE_TABLE_TEST);
    }

@Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        db.execSQL("DROP TABLE IF EXISTS "+TABLE_TEST);
        db.execSQL("DROP TABLE IF EXISTS "+TABLE_ANSWER);
        onCreate(db);
    }

I put this in oncreate..:

 dbClass=new database(this);        
    try
    {
        Log.w("inside ",  " database opened");///This gets printed
        dbLite=dbClass.getWritableDatabase();
        Log.w("after ",  " database opened");///This get printed
    }
    catch(Exception c)
    {
        Log.v("Open database exception caught", c.getMessage());
        dbLite=dbClass.getReadableDatabase();
    }

Nothing in the onCreate gets printed..

It is as if onCreate never gets called

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:30:26+00:00Added an answer on May 27, 2026 at 4:30 am

    Your foreign key isn’t made correctly

    http://www.sqlite.org/foreignkeys.html

    for more information

    private static final String CREATE_TABLE_QUESTION=
    " create table " + TABLE_ANSWER +
    " (question_id integer primary key autoincrement," +
    COL_ANSWER_1+ " text not null,"+ 
    COL_ANSWER_2+" text not null," +
    COL_ANSWER_3+" text not null," +
    COL_ANSWER_4+" text not null," +
    COL_ANSWER_5+ " text not null,"+ 
    COL_ANSWER_6+" text not null," +
    COL_RIGHT_ANSWER+" integer," +
    COL_WRONG_ANSWER+" integer, " +
    COL_TEST_ID+" INTEGER, " + 
    "FOREIGN KEY(" + COL_TEST_ID + ") REFERENCES " + TABLE_TEST+"(test_id))";
    

    should do the trick

    furtermore your onCreate method only executes when the database gets created, not when upgraded
    you should override onUpgrade to perform an update (or test on a new device/emulator)

    http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onUpgrade(android.database.sqlite.SQLiteDatabase,%20int,%20int)

    if you extend sqliteOpenHelper then you need to call the super-constuctor with your newVersionId to trigger onUpgrade

    public YourDatabase(Context context) {
        super(context, DatabaseName, null, DATABASE_VERSION);
    }
    

    Tip: uninstall the application from your phone/emulator completely and reinstall it (then db will be removed and it will be created definately, if not the problem is somewhere else)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am following a tutorial, and trying to create a database, then add put
I have the following two classes: TcmTPDataPanel = class(TcmTPBasePanel) Database: TnxDatabase; Session: TnxSession; private
For database connection from PHP to MSSQL, I had create the following code. Can
In the following code, the object constructed in the last line of 'main()', seems
How can I construct the following string in an Excel formula: Maurice "The Rocket"
I have the following code that is able to create a class that has
I have been sharing database variables using the following code: Namespace DataAccessVariables Public Class
I have the following class Person: public class Person { public string Name {
I currently have the following code that retrieves data from the database and then
I have the following LINQ query that returns two objects from my database. These

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.