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 6972001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:54:42+00:00 2026-05-27T16:54:42+00:00

I have a database that I want to add a column to, I changed

  • 0

I have a database that I want to add a column to, I changed the static database version but when I run the program on my device the new column is still not there so I am guessing my onUpdate is not getting called and I am not sure why.

this is how I create the database

     private static class DatabaseHelper extends SQLiteOpenHelper 
    {
        DatabaseHelper(Context context) 
        {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) 
        {
            createTables(db);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, 
                              int newVersion) 
        {
            Log.w("CalendarDB", "Upgrading database from version " + oldVersion 
                  + " to "
                  + newVersion + ", which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS Events_Table");
            onCreate(db);
        }

        private void createTables(SQLiteDatabase db){
            db.execSQL("CREATE TABLE " + EVENTS_TABLE + "(" + ID + " integer primary key autoincrement, " +
                    EVENT + " TEXT, " + LOCATION + " TEXT, " + DESCRIPTION + " TEXT, " + DATE + " TEXT, " + START + " LONG, " + END + " TEXT, " + REAL_START_TIME + " TEXT," 
                    + REAL_END_TIME + " TEXT," + COLOR + " TEXT, " + BLINK + " TEXT, " + VIBRATE + " TEXT, " + RING_TONE_PATH + " TEXT, " + ICON + " TEXT, " + REMINDERS +
                    " TEXT, " + START_WITH_REMINDER + " TEXT, " + CALENDAR_ID + " TEXT, " + EVENT_ID + " TEXT);");
        }
    }

is there something else I have to do to get the onUpdate to get called? I tried following this answer but still no result

  • 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-27T16:54:43+00:00Added an answer on May 27, 2026 at 4:54 pm

    In order to upgrade the Database in Android you should increment the DATABASE_VERSION by one, in order for the SQLOpenHelper to know that it must called the onUpgrade method.

    Rembember

    This only work when you call getWritableDatabase() otherwise it won’t upgrade. And if you change the version and call getReadableDatabase it will show an exception

    throw new SQLiteException("Can't upgrade read-only database from version " +
                            db.getVersion() + " to " + mNewVersion + ": " + path);
    

    But Why?
    You see when you call getWritableDatabase the code check wether the version is the same:

    if (version != mNewVersion) {
                    db.beginTransaction();
                    try {
                        if (version == 0) {
                            onCreate(db);
                        } else {
                            if (version > mNewVersion) {
                                onDowngrade(db, version, mNewVersion);
                            } else {
                                onUpgrade(db, version, mNewVersion);
                            }
                        }
                        db.setVersion(mNewVersion);
                        db.setTransactionSuccessful();
                    } finally {
                        db.endTransaction();
    }
    }
    

    Update

    Well turns out that it should work with getReadableDatabase() since in the code you always are getting a WrittableDatabase too. So it should work with both method, here is the documentation for getReadableDatabase():

    Create and/or open a database. This will be the same object returned
    by getWritableDatabase() unless some problem, such as a full disk,
    requires the database to be opened read-only. In that case, a
    read-only database object will be returned. If the problem is fixed, a
    future call to getWritableDatabase() may succeed, in which case the
    read-only database object will be closed and the read/write object
    will be returned in the future.

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

Sidebar

Related Questions

I have a column in my database that is typed double and I want
I have a VB6 program that adds a column to an MS Access database
I have a database table that i want to allow my friends to update.
I have a MySQL database that I want to archive . What is the
I have a Database table that I want to display in a DataGridView. However,
I have a test environment for a database that I want to reload with
I have an old SQL Server 2000 database that I want to get into
I have a string being returned from my database that I want to use
I have a database schema in SQL 2005 that I want to copy to
I have a database field called abCode , that I want to map to

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.