データベースの会議と議事録のテーブルのフィールドを変更し、データベースのバージョンを 1 から 3 に変更しました。エミュレーターでアプリを実行すると、テーブルがまだ存在するというエラーが表示されます。テーブルをドロップするにはどうすればよいですか?
丸太の猫:
05-31 15:30:32.338: E/AndroidRuntime(20347): android.database.sqlite.SQLiteException: table Meeting already exists: , while compiling: create table Meeting (_id integer primary key autoincrement, meet text not null, venue text not null, agenda text not null, time text not null, date text not null, phoneNo text not null, email text not null);
05-31 15:30:32.338: E/AndroidRuntime(20347): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
データベース コード:
public class DBUserAdapter
{
public static final String KEY_ROWID = "_id";
private static final String TAG = "DBAdapter";
public static final String KEY_ROWID2 = "_id1";
private static final String DATABASE_NAME = "usersdb";
private static final String DATABASE_TABLE = "Meeting";
private static final String DATABASE_TABLE1 = "minutes";
private static final int DATABASE_VERSION = 3;
private static final String DATABASE_CREATE =
"create table Meeting (_id integer primary key autoincrement, "
+ "meet text not null, "
+ "venue text not null, "
+ "agenda text not null, "
+ "time text not null, "
+ "date text not null, "
+ "phoneNo text not null, "
+ "email text not null);";
private static final String MINUTES_TABLE_CREATE =
"create table minutes (_id1 integer primary key autoincrement, "
+ "meet text not null, "
+ "minutes text not null,";
private SQLiteDatabase db;
public DBUserAdapter(Context ctx)
{
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
private static class DatabaseHelper extends SQLiteOpenHelper
{
DatabaseHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL(DATABASE_CREATE);
db.execSQL(MINUTES_TABLE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
Log.w(TAG, "Upgrading database from version " + oldVersion
+ " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS DATABASE_TABLE ");
db.execSQL("DROP TABLE IF EXISTS DATABASE_TABLE1 ");
onCreate(db);
}
}
onupgrade() がどのように機能するのか混乱していますか? 私は何をすべきか?テーブルをドロップするには?