Reputation: 1298
I have the following entity in my project -
@Entity(tableName = "query_table")
public class QueryModel {
@PrimaryKey
private int ID;
private int productID;
private String vendorName;
private String productName;
private String lateTimeUpdated;
public QueryModel(String vendorName, String productName, String lateTimeUpdated, int productID) {
this.vendorName = vendorName;
this.productName = productName;
this.lateTimeUpdated = lateTimeUpdated;
this.productID = productID;
}
public int getID() {
return ID;
}
public void setID(int ID) {
this.ID = ID;
}
public int getProductID() {
return productID;
}
public void setProductID(int productID) {
this.productID = productID;
}
public String getVendorName() {
return vendorName;
}
public void setVendorName(String vendorName) {
this.vendorName = vendorName;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getLateTimeUpdated() {
return lateTimeUpdated;
}
public void setLateTimeUpdated(String lateTimeUpdated) {
this.lateTimeUpdated = lateTimeUpdated;
}
}
for some reasons, I get the following error when starting to populate the local db -
UNIQUE constraint failed: query_table.ID (code 1555 SQLITE_CONSTRAINT_PRIMARYKEY[1555]
I understand it has something to do with me getting the same value again and again and overriding it which makes it crash, but how can I fix it?
Upvotes: 1
Views: 3358
Reputation: 94
On the constructor you don't pass the id
field and as I can see you don't initialize it in general.
@PrimaryKey(autoGenerate = true)
private int ID;
If you go like this, does anything change? How can it be Primary key if it is null?
Upvotes: 3