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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:09:06+00:00 2026-05-22T21:09:06+00:00

I am trying to upgrade a certain table by adding a column to a

  • 0

I am trying to upgrade a certain table by adding a column to a Sqlite table in my android app.I have added an alter table statement in the onUpgrade method of my DBHelper.

Here are the problems that I am seeing
I changed the value of Database version from 1 to 2, so ideally now the onUpgrade should get called.It does get called, but it gets called everytime I instantiate the class.As a result I get a column already exists error.

Here is the onUpgrade method

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, 
    int newVersion) 
    {
        Log.d("old Version",oldVersion+"");
        Log.d("New Version",newVersion+"");
        db.beginTransaction();

        try
        {           
            String DATABASE_UPGRADE;
            DATABASE_UPGRADE="alter table "+DATABASE_TABLE_MESSAGES+" ADD COLUMN  "+ IS_READ+ " integer DEFAULT 0;";
            db.execSQL(DATABASE_UPGRADE);
            Log.d("upgrade", "Successful");
            db.setTransactionSuccessful();
        } 


    finally 
    {
        db.endTransaction();
    }

    }
}    

I am wondering why the onUpgrade gets called each time!!!

  • 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-22T21:09:07+00:00Added an answer on May 22, 2026 at 9:09 pm

    In the constructor of your database helper are you correctly passing the new version number?

    EDIT: should look like this

    DatabaseHelper(Context context)
            {
                super(context, DATABASE_NAME, null, DATABASE_VERSION);
            }
    

    and DATABASE_VERSION should be 2.

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

Sidebar

Related Questions

I am trying to upgrade my previous version app into the Android market,but it
I'm trying to upgrade my subversion server (I have it hosted with Dreamhost) This
I'm trying to upgrade an app ( Clarke ) to provide 10.6 compatibility. My
I've been trying to use smart pointers to upgrade an existing app, and I'm
Trying to upgrade a fairly complicated app from rails 3.0 to rails 3.1, suddently
When trying to upgrade Android SDK Tools to revision 16, I am getting the
I am trying to upgrade the tapestry version from 5.1.0.5 to 5.2.6. I have
I'm trying to upgrade Rails 3 on OS X 10.6. I currently have gem
Trying to upgrade an MFC app to use the new MFC feature pack, we
I am trying to upgrade my app so that it looks normal on the

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.