title: Table has no column named [variable]?
body: <p>I have set up a new table in my database. I have other existing tables that work fine, but this newest one came later and is proving problematic.</p>
  
  <p>The table in question is the bar table. I have checked the structure of the database from SQLite Database Browser and I see the column I expected. There appears to be 3 possibilities.</p>
  
  <p>1) The database was not created properly - but I can see the column so I think this is unlikely?</p>
  
  <p>2) There is a problem with my input method - I have similar methods implemented for other tables.</p>
  
  <p>3) There is a problem with upgrading my database version </p>
  
  <p>I have truncated much of the code to isolate only the important parts.</p>
  
  <pre><code>public class DBmanager {
  
  private static final String DATABASE_NAME = "DBmanagerdb";
  private static final int DATABASE_VERSION = 1;
  
  // Shared strings and main table
  private static final String DATABASE_TABLE = "drinkTable";
  public static final String KEY_ROWID = "_id";
  public static final String KEY_NAME = "drink_name";
  public static final String KEY_BAR = "bar_name";
  public static final String KEY_SCORE = "drink_score";
  public static final String KEY_VOL = "volume";
  public static final String KEY_PRICE = "price";
  public static final String KEY_DRINKABV = "abv";
  public static final String KEY_FAVE = "favorite";
  public static final String MYTAB_DRINKCOUNT = "mytab_drinkCount";
  
  // Strings for ABV
  private static final String ABV_TABLE = "abvTable";
  public static final String KEY_ABV_ID = "_id";
  public static final String KEY_NAME_ABV = KEY_NAME;
  public static final String KEY_ABV = "abv_value";
  
  //
  private static final String VERSION_TABLE = "versionTable";
  public static final String VERSION_NUMBER = "version";
  
  private static final String BAR_TABLE = "barTable";
  private static final String KEY_LAT = "barLatitude";
  private static final String KEY_LONG = "barLongitude";
  public static final String KEY_BARID = "barId";
  
  // Strings for My Tab
  
  ;
  
  private DbHelper ourHelper;
  private final Context ourContext;
  private SQLiteDatabase ourDatabase;
  
  private static class DbHelper extends SQLiteOpenHelper {
  
      public DbHelper(Context context) {
          super(context, DATABASE_NAME, null, DATABASE_VERSION);
  
          // TODO Auto-generated constructor stub
      }
  
      @Override
      public void onCreate(SQLiteDatabase db) {
          // TODO Auto-generated method stub
          db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID
                  + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_BAR
                  + " TEXT NOT NULL, " + KEY_NAME + " TEXT NOT NULL, "
                  + KEY_PRICE + " DOUBLE, " + KEY_VOL + " DOUBLE, "
                  + KEY_DRINKABV + " DOUBLE, " + KEY_SCORE + " DOUBLE,"
                  + MYTAB_DRINKCOUNT + " INTEGER," + KEY_FAVE + " INTEGER);");
  
          db.execSQL("CREATE TABLE " + ABV_TABLE + " (" + KEY_ABV_ID
                  + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME_ABV
                  + " TEXT NOT NULL, " + KEY_ABV + " DOUBLE);");
  
          db.execSQL("CREATE TABLE " + VERSION_TABLE + " (" + KEY_ROWID
                  + " INTEGER PRIMARY KEY AUTOINCREMENT, " + VERSION_NUMBER
                  + " INTEGER);");
  
          db.execSQL("CREATE TABLE " + BAR_TABLE + " (" + KEY_ROWID
                  + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_BAR
                  + " TEXT NOT NULL, " + KEY_LAT + " TEXT NOT NULL, " + KEY_LONG
                  + " TEXT NOT NULL);");
  
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
          // TODO Auto-generated method stub
          newVersion = oldVersion;
          Log.i("Values", "OldVersion: " + oldVersion + "     New Version: "
                  + newVersion);
  
          db.execSQL("DROP TABLE IF EXISTS " + BAR_TABLE);
          onCreate(db);
  
      }
  
  }
  
  public long enterNewBar(String barName) {
  
      ContentValues cv = new ContentValues();
      cv.put(KEY_BAR, barName);
      cv.put(KEY_LAT, "hello");
      cv.put(KEY_LONG, "world");
      return ourDatabase.insert(DATABASE_TABLE, null, cv);
  }
  
  public boolean checkUniqueBar(String barName) {
  
      boolean flag = false;
  
      String myQuery = "SELECT DISTINCT " + KEY_BAR + " FROM "
              + DATABASE_TABLE;
  
      Cursor c = ourDatabase.rawQuery(myQuery, null);
      if (c != null) {
  
          for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
              if (c.getString(c.getColumnIndex(KEY_BAR)) == barName) {
                  flag = true;
  
              }
          }
          c.close();
  
      }
      return flag;
  }
  </code></pre>
  
  <p>Stacktrace:</p>
  
  <pre><code>  05-22 00:53:56.859: E/SQLiteLog(8496): (1) table drinkTable has no column named barLongitude
      05-22 00:53:56.909: E/SQLiteDatabase(8496): Error inserting barLongitude=world barLatitude=hello bar_name=TEst
      05-22 00:53:56.909: E/SQLiteDatabase(8496): android.database.sqlite.SQLiteException: table drinkTable has no column named barLongitude (code 1): , while compiling: INSERT INTO drinkTable(barLongitude,barLatitude,bar_name) VALUES (?,?,?)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at android.database.sqlite.SQLiteProgram.&lt;init&gt;(SQLiteProgram.java:58)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at android.database.sqlite.SQLiteStatement.&lt;init&gt;(SQLiteStatement.java:31)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at mjd.mdflip.areyoudrunk.DBmanager.enterNewBar(DBmanager.java:555)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at mjd.mdflip.areyoudrunk.fragments.MainFrag.calculateScore(MainFrag.java:288)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at mjd.mdflip.areyoudrunk.fragments.MainFrag.onClick(MainFrag.java:145)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at android.view.View.performClick(View.java:4204)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at android.view.View$PerformClick.run(View.java:17355)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at android.os.Handler.handleCallback(Handler.java:725)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at android.os.Handler.dispatchMessage(Handler.java:92)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at android.os.Looper.loop(Looper.java:137)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at android.app.ActivityThread.main(ActivityThread.java:5041)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at java.lang.reflect.Method.invokeNative(Native Method)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at java.lang.reflect.Method.invoke(Method.java:511)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
      05-22 00:53:56.909: E/SQLiteDatabase(8496):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>