gpt4 book ai didi

android - 自动增量在 android SQLite 数据库中不起作用

转载 作者:行者123 更新时间:2023-11-29 16:05:22 24 4
gpt4 key购买 nike

我有一个正在运行的数据库,但主键不会自动递增。有谁知道是什么问题?

代码如下

    // Database name and Version
private static final String DATABASE_NAME = "kmky_database.db";
private static final int DATABASE_VERSION = 1;

// Database Table
private static final String TABLE_NAME = "logs";
private static final String COLUMN_ID = "_id";
private static final String COLUMN_PHONENUMBER = "phonenumber";
private static final String COLUMN_TYPE = "type";
private static final String COLUMN_DATE = "timestamp";
private static final String COLUMN_INCOMING = "incoming";
private static final String COLUMN_OUTGOING = "outgoing";
private static final String DATABASE_CREATE = "CREATE TABLE " + TABLE_NAME + "(" + COLUMN_ID + " INTEGER PRIMARY KEY, " + COLUMN_PHONENUMBER + " TEXT, " + COLUMN_TYPE + " TEXT, " + COLUMN_DATE + " INTEGER, " + COLUMN_INCOMING + " INTEGER, " + COLUMN_OUTGOING + " INTEGER);";

最佳答案

你必须这样创建主键

  ...."(" + COLUMN_ID + "  INTEGER PRIMARY KEY AUTOINCREMENT.....

你忘记了 AUTOINCREMENT 关键字,仅此而已。

关于android - 自动增量在 android SQLite 数据库中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19209222/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com