如何使用SQLite创建具有4列的表 [英] How to create a table with 4 columns using SQLite

查看:52
本文介绍了如何使用SQLite创建具有4列的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在android studio中的一个应用程序中工作,该应用程序使用SQLite将用户的信息传递到表中.它正在工作,但是我需要添加其他数据,所以根据我的说法,我将表转换为4列中的另一列,但是在logcat中出现此消息

I was working in android studio in an app that passes the user's info to a table using SQLite. It was working but I needed to add another data so according to me I convert the table to another of 4 columns but in the logcat appears this message

"E/SQLiteLog:(1)表STUDENTS有3列,但提供了4个值"

"E/SQLiteLog: (1) table STUDENTS has 3 columns but 4 values were supplied"

这就是我所拥有的:

public class SQLiteDb extends SQLiteOpenHelper {

    private static final String TABLE_STUDENTS="CREATE TABLE STUDENTS(NAMES TEXT, 
    LASTNAMES TEXT, ID TEXT, IMAGE TEXT)";

    public SQLiteDb(Context context) {
        super(context, "db_students", null, 1);
    }
}

有人知道如何修复它以接受4个值吗?

Does anyone know how can I fix it to accept 4 values?

推荐答案

列似乎不存在的典型原因是对数据库助手的 onCreate 方法的误解,它是假定它在每次运行该应用程序时都运行.实际上,它将仅在首次创建数据库时自动运行一次(创建后数据库将保留一次).

The typical reason why columns don't appear to exist is the mis-conception about the Database Helper's onCreate method and that it is assumed that it runs every time the App is run. In fact it will only run automatically once when the database is first created (once created the database remains).

因此,您很可能在创建数据库后将表更改为具有附加列.

Hence it is likely that you have changed the table to have an additional column after the database has been created.

解决方法很简单,要么删除应用程序的数据,要么卸载应用程序,然后执行一次,然后重新运行应用程序,新的架构将被应用,您将拥有四列.

The fix is simple either delete's the App's data or uninstall the App, after doing one then rerun the App and the new schema will be applied and you will have the four columns.

这篇关于如何使用SQLite创建具有4列的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆