SQLite列错误:表XXX没有名为YYY的列 [英] SQLite column error: table XXX has no column named YYY

查看:102
本文介绍了SQLite列错误:表XXX没有名为YYY的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了以下内容,但没有发现与我的问题相符的内容(据我所知):

I've looked at the following, among others and have found nothing that matches my problem (as far as I can tell):

android.database.sqlite.SQLiteException:表X没有列名为Y:,同时进行编译:INSERT INTO

Android : Table has no column named "variable name" MySql Database error

将插入的错误编译:没有名为ID的列

Android SQLite问题-表...没有名为

< a href = https://sqlite.org/foreignkeys.html rel = nofollow noreferrer> https://sqlite.org/foreignkeys.html

我收到以下SQLite错误:

I'm getting the following SQLite error:

SQLiteDatabase: Error inserting zipCode=23456 address2= city=state address1=123 petName=qwerty phoneNumber=null vetName=zaw emailAddress=
                                             android.database.sqlite.SQLiteException: table vets has no column named petName (code 1): , while compiling: INSERT INTO vets (zipCode,address2,city,address1,petName,phoneNumber,vetName,emailAddress) VALUES (?,?,?,?,?,?,?,?)

我觉得这与VetTable中的外键有关,但是我的研究还没有t帮助我了解发生了什么。

I have a feeling that it has to do with the foreign key in VetTable but my research hasn't helped me with understanding what's going on.

VetTable的定义如下:

VetTable is defined as follows:

public class VetTable {
    public static final String TABLE_VETS = "vets";
    public static final String VET_ID = "vetId";
    public static final String PET_ID = "petId";
    public static final String VET_NAME = "vetName";
    public static final String ADDRESS1 = "address1";
    public static final String ADDRESS2 = "address2";
    public static final String CITY = "city";
    public static final String STATE = "state";
    public static final String ZIP_CODE = "zipCode";
    public static final String PHONE_NUMBER = "phoneNumber";
    public static final String EMAIL_ADDRESS = "emailAddress";

public static final String SQL_CREATE =
        "CREATE TABLE " + TABLE_VETS + "(" +
                VET_ID + " INTEGER PRIMARY KEY UNIQUE, " +
                PET_ID + " INTEGER, " +
                VET_NAME + " TEXT, " +
                ADDRESS1 + " TEXT, " +
                ADDRESS2 + " TEXT, " +
                CITY + " TEXT, " +
                STATE + " TEXT, " +
                ZIP_CODE + " TEXT, " +
                PHONE_NUMBER + " TEXT, " +
                EMAIL_ADDRESS + " TEXT, " +
                "FOREIGN KEY(" + PET_ID + ") " +
                "REFERENCES pets(petId));";

    public static final String SQL_DELETE =
            "DROP TABLE" + TABLE_VETS;
}

DBHelper代码中的相关代码如下:

The relevant code from DBHelper code is as follows:

public void addVetInfo(String name, String address1, String address2, String city, String state, String zip, String phone, String email){
    try {
        db = this.getWritableDatabase();
        values.put(VET_NAME, name);
        values.put(ADDRESS1, address1);
        values.put(ADDRESS2, address2);
        values.put(CITY, city);
        values.put(CITY, state);
        values.put(ZIP_CODE, zip);
        values.put(PHONE_NUMBER, phone);
        values.put(EMAIL_ADDRESS, email);
        db.insert(TABLE_VETS, null, values);
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

可以看出petName不属于也不属于曾经包含在VetTable中,也不是addVetInfo中参数列表的一部分。那么,SQLite在做什么呢,使它认为petName应该是VetTable中的一列?

As can be seen petName is not part of nor has ever been included in VetTable, nor is it part of the argument list in addVetInfo. So, what is SQLite doing that makes it think that petName should be a column in VetTable?

推荐答案

试图将数据插入到不存在列名的表中,或者您试图插入的模式已被最新的sequelize.js代码更改。

This can happen when you are trying to insert the data into the table where the column name does not exist or maybe schema that you are trying to insert into has been changed with the latest sequelize.js code.

可能的问题示例:


  • 重命名的列名(例如:更早的 ID 和现在的 UUID

  • 新的架构设计或完整的表架构更改

  • 尝试将具有错误字段名称(例如: IDS :1234)的数据插入具有列名称(例如: ID :1234)

  • Renamed column name (eg: earlier ID and now UUID)
  • New schema design or complete table schema change
  • Trying to insert the data with the wrong field name (eg: IDS: 1234) into the table with the column name (eg: ID: 1234)

这篇关于SQLite列错误:表XXX没有名为YYY的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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