SQLiteLog:(1)靠近" manId"在android中一起加入表时出现语法错误

时间:2014-06-04 10:11:00

标签: android sqlite android-sqlite

我正在加入三个表MANUFACTURERS_TABLETBL_JOB_ADDRESSTBL_APPLIANCES,而在TBL_APPLIANCES中创建两个外键,会出现问题标题中所述的错误。看了之前的问题&回答,我没有犯这些问题中列出的错误。

制造商表

//columsn for manufacturer table
public static final String KEY_MANROWID = "manId";   // error-some
public static final String KEY_MANFACTURERNAME = "manufacturer_name";

JobAddress表

//columsn for job address table
public static final String KEY_JOB_ADDRESSROWID = "_id";
public static final String KEY_ADDRESSOFPLACE = "address_of_place";

设备表

public static final String KEY_APPLIANCES_ROWID = "appliances_id";
public static final String KEY_APPLIANCES_MANIFACTURERS_ID = "appliance_manufacturers_id";

public static final String KEY_APPLIANCES_MODEL = "appliances_model";
public static final String KEY_APPLIANCES_TYPE = "appliances_type";
public static final String KEY_APPLIANCES_SERIAL = "appliances_serial";
public static final String KEY_APPLIANCES_SERVICE_INTERVAL=  
    "appliances_service_interval";
public static final String KEY_APPLIANCES_JOB_ADDRESS_ID =    
    "appliances_jobaddress_id";
public static final String KEY_APPLIANCES_ENGINEERS_ID = "appliances_engineers_id";
public static final String KEY_APPLIANCES_DATE = "appliances_date";

使用两个密钥创建设备表

// appliance table referencing manufacturers & job adress table
        db.execSQL("CREATE TABLE " + TBL_APPLIANCES + " (" 
                    + KEY_APPLIANCES_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                    + KEY_APPLIANCES_MODEL + " TEXT NOT NULL, "
                    + KEY_APPLIANCES_TYPE + " TEXT NOT NULL, "
                    + KEY_APPLIANCES_SERIAL + " TEXT NOT NULL, "
                    + KEY_APPLIANCES_SERVICE_INTERVAL + " TEXT NOT NULL, " 
                    + KEY_APPLIANCES_DATE + " TEXT NOT NULL, "
                    + KEY_JOB_ADDRESSROWID + " INTEGER, "
                    + " FOREIGN KEY ("+KEY_APPLIANCES_JOB_ADDRESS_ID+") REFERENCES "+TBL_JOB_ADDRESS+" ("+KEY_JOB_ADDRESSROWID+") "
                    + KEY_MANROWID + " INTEGER, "
                    + " FOREIGN KEY ("+KEY_APPLIANCES_MANIFACTURERS_ID+") REFERENCES "+MANUFACTURERS_TABLE+" ( "+KEY_MANROWID+" ));"
                );

1 个答案:

答案 0 :(得分:1)

FOREIGN KEY等表约束必须在列规范之后。

移动

+ KEY_MANROWID + " INTEGER, "

高于FOREIGN KEY约束。