本文介绍了在Android中,确实_id必须在任何表格present产生的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个表只能有一个外键,而不是主键。我得到这个错误:

  java.lang.IllegalArgumentException异常:列'_id'不存在

我读的主键必须_id,没有解释的教程。这是罚款。但是,如果我不想要一个主键!如果我只想要一个外键。我假定这是我的问题所在。下面的模式是什么,我有。但第三个是我认为这是来自哪里。

  database.execSQL(CREATE TABLE事件(+
            _id INTEGER PRIMARY KEY,EVENT_NAME TEXT+
            ));database.execSQL(CREATE TABLE提醒(_id INTEGER PRIMARY KEY,EVENT_NAME TEXT+
            ));database.execSQL(CREATE TABLE events_info(_id INTEGER,EVENT_NAME TEXT,INTEGER ALL_DAY,+
                    起始日期INTEGER,INTEGER START_TIME日期,结束日期INTEGER,INTEGER end_time时间,+
                    位置文本,reminder_id INTEGER,指出文本,重复TEXT,+
                    外键(_id)参考事件(_id),外键(reminder_id)参考文献提醒(_id))
                    );


解决方案

您使用的是的CursorAdapter ?因为如果你的的CursorAdapter 类需要有一个名为列 _id 否则类将无法正常工作。一般情况下,它通常被认为是很好的做法,有你的数据库表包含一个名为列 _id 因为这个原因,如果你决定将数据绑定到的CursorAdapter 或它的一个子类。

I am trying to create a table to only has a foreign key, not a primary key. I am getting this error:

java.lang.IllegalArgumentException: column '_id' does not exist

I read a tutorial that the primary key must be _id, with no explanation. And that is fine. But what if I do not want a primary key! What if I only want a foreign key. I am assuming this is where my problem lies. The schemas below are what I have. But the third one is where I assume this is coming from.

database.execSQL("CREATE TABLE events (" +
            "_id INTEGER PRIMARY KEY, event_name TEXT" +
            ")");

database.execSQL("CREATE TABLE reminders(_id INTEGER PRIMARY KEY, event_name TEXT" +
            ")");

database.execSQL("CREATE TABLE events_info (_id INTEGER, event_name TEXT, all_day INTEGER, " +
                    "start_date INTEGER, start_time INTEGER, end_date INTEGER, end_time INTEGER," +
                    " location TEXT, reminder_id INTEGER, notes TEXT, repeat TEXT," +
                    "FOREIGN KEY(_id) REFERENCES events(_id), FOREIGN KEY(reminder_id) REFERENCES reminders(_id))"
                    );
解决方案

Are you using a CursorAdapter? Because if you are, the CursorAdapter class requires that there is a column named _id or else the class will not work. In general, it's often considered good practice to have your database tables contain a column named _id for this reason, in case you ever decide to bind your data to a CursorAdapter or one of its subclasses.

这篇关于在Android中,确实_id必须在任何表格present产生的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 02:29