0
私は最初にテーブルを作成して、すべてがうまくいきました。それから私はテーブルフィールドを追加する必要がありました。今私はそれに書き込むとき、私は新しい列が存在しないと言うエラーを取得します。コンテンツプロバイダのテーブルを再作成するにはどうすればよいですか? 2へAndroid - 契約する新しい列を追加しました。テーブルのリセットが必要
public static final class InventoryEntry implements BaseColumns {
public static final Uri CONTENT_URI = Uri.withAppendedPath(InventoryContract.BASE_CONTENT_URI, InventoryEntry.TABLE_NAME);
public static final int STOCK_MIN = 0;
public static final String TABLE_NAME = "products"; // Same as PATH
public static final String CONTENT_LIST_TYPE =
ContentResolver.CURSOR_DIR_BASE_TYPE + "/" + CONTENT_AUTHORITY + "/" + TABLE_NAME;
public static final String CONTENT_ITEM_TYPE =
ContentResolver.CURSOR_ITEM_BASE_TYPE + "/" + CONTENT_AUTHORITY + "/" + TABLE_NAME;
public static final String COLUMN_PRODUCT_ID = "_id";
public static final String COLUMN_PRODUCT_NAME = "product_name";
public static final String COLUMN_PRODUCT_DESC = "product_description";
public static final String COLUMN_PRODUCT_IMG_PATH = "product_img_path";
public static final String COLUMN_PRODUCT_STOCK = "product_stock";
public static final String CREATE_TABLE = "CREATE TABLE " + InventoryEntry.TABLE_NAME + " ("
+ InventoryEntry.COLUMN_PRODUCT_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ InventoryEntry.COLUMN_PRODUCT_NAME + " TEXT NOT NULL UNIQUE, "
+ InventoryEntry.COLUMN_PRODUCT_DESC + " TEXT NOT NULL, "
+ InventoryEntry.COLUMN_PRODUCT_IMG_PATH + " TEXT DEFAULT '', "
+ InventoryEntry.COLUMN_PRODUCT_STOCK + " INTEGER NOT NULL CHECK (" + InventoryEntry.COLUMN_PRODUCT_STOCK + " >= " + STOCK_MIN + "));";
}
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "products.db";
public static final int DATABASE_VERSION = 1;
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// Execute the SQL statement
db.execSQL(InventoryContract.InventoryEntry.CREATE_TABLE);
}
// Called when database is upgraded.
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// The database is still at version 1, so there's nothing to do be done here.
}
}
インストールします。テーブルはまだ列を追加しませんでした – ryanwaite28