![](/img/trans.png)
[英]How can I create a table in my postgres db with Spring Boot?
[英]How can I create a table in my DB, after dropping all of my tables in database?
我用這個查詢在DB
中看到我的表,..
(SELECT name
FROM sqlite_master
WHERE type ='table' AND name NOT LIKE 'sqlite_%';)
在(刪除 allmytable)之后我無法創建表,...
package com.ariaz.amirmkaa.litner002;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseManager extends SQLiteOpenHelper {
public DatabaseManager(Context context)
{
super(context, "myDB", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
String card_tbl = "CREATE TABLE \"cards_tbl\" (\n" +
"\t\"id\"\tINTEGER NOT NULL,\n" +
"\t\"questiontx\"\tTEXT NOT NULL,\n" +
"\t\"questionpic\"\tBLOB,\n" +
"\t\"solutiontx\"\tTEXT NOT NULL,\n" +
"\t\"solutionpic\"\tBLOB,\n" +
"\t\"days\"\tINTEGER NOT NULL,\n" +
"\t\"bookid\"\tINTEGER NOT NULL,\n" +
"\t FOREIGN KEY (bookid)\n" +
" REFERENCES book_tbl (bookid)\n" +
");";
db.execSQL(card_tbl);
}
我相信您的問題是onCreate方法僅在首次創建數據庫時運行(即如果數據庫文件不存在),只要數據庫存在,它就不會運行。
刪除從 sqlite_master 中提取的所有表不會刪除數據庫,數據庫將至少具有sqlite_master表,該表由於受到保護而無法刪除。
當您刪除所有表時,您可以調用onCreate方法。
super(context, "myDB", null, 1);
傳遞的第四個參數)以及opUpdate
方法中的適當遷移代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.