title: SQLITE - setting the version of a new database
body: <p>I have used this example to create a database that I copy over on a fresh install</p>
  
  <p><a href="http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/" rel="noreferrer">http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/</a></p>
  
  <p>Problem I have now is I have now done some updates to the database and I asummed I also do this updates to the master file within the build so the users always get the most update version on new install</p>
  
  <p>I have a different class that deals with all the db calls query statements.</p>
  
  <p>I have set this line</p>
  
  <pre><code>private static final int DATABASE_VERSION = 5;
  </code></pre>
  
  <p>On a fresh install now the database is copied over correctly but when the query class calls the databasehelper again the onupgrade() method is called and tries to update to the latest version and the app crashes as it is trying to do upgrades that cannot be done</p>
  
  <p>I was under the understanding that the following set the database version on fresh installs or is this wrong. If so how do I set the database version for new installs</p>
  
  <pre><code>public DatabaseHelper(Context context) {
          super(context, DB_NAME, null, DATABASE_VERSION);
          this.context = context;
      }
  </code></pre>
  
  <p>just for completness here is a sample of the onupgrade()</p>
  
  <pre><code>@Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  
          dbUpgrade = new DatabaseUpgrades(context);
  
          Log.d(DEBUG_TAG, "Calling onupgrade db");
          Log.d(DEBUG_TAG + " : " + DatabaseHelper.class.getName(),
                  "Upgrading database from version " + oldVersion + " to "
                      + newVersion);
  
          if (oldVersion == 1) {
              Log.d(DEBUG_TAG, "Updating to Version 2");
              dbUpgrade.upgradeDB2(db);
              oldVersion++;
          }
  }
  </code></pre>
  
  <p>Question what version is the new database set to on a fresh install and how can you overwrite it if it is not version 5</p>
  
  <p>Thanks</p>