[英]Table not creating on android device but creating on the virtual device
So I am trying to create a Database and a table in android studio.所以我试图在 android 工作室中创建一个数据库和一个表。 The database is created successfully but table is not creating when I am using my android phone but both the database and the table are created when I use Virtual device from the AVD.当我使用我的 android 手机时,数据库已成功创建,但未创建表,但当我使用 AVD 中的虚拟设备时,数据库和表均已创建。
public class Databases extends SQLiteOpenHelper {
public static final String dbname = "AttendanceDb11";
public Databases(@Nullable Context context) {
super(context, dbname, null, 2);
}
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_TABLE = "CREATE TABLE Student12 ( _id INTEGER PRIMARY KEY AUTOINCREMENT, Name Text)";
db.execSQL(CREATE_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
db.execSQL("Drop table if exists Student12");
onCreate(db);
}
}
Here is my code这是我的代码
It looks like that app was already installed before you created the tables.看起来该应用程序在您创建表之前已经安装。 I would do one of the following:我会执行以下操作之一:
1: Uninstalling and re-installing the app. 1:卸载并重新安装应用程序。
2: The best and better approach is to drop and recreate table in onUpdate method, and increase the db version whenever you change the schema. 2:最好和更好的方法是在 onUpdate 方法中删除并重新创建表,并在更改架构时增加数据库版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.