I read a lot of subject abaout this problem. but i don't solve a solution for mine.
i create two table : Polluant & Alerte . in Alerte , i have define foreign key the id of polluant. here is the creation code of table :
CREATE TABLE IF NOT EXISTS Polluant (
idPol int(3) PRIMARY KEY AUTOINCREMENT,
nom varchar(10) UNIQUE NOT NULL,
unite varchar(10) NOT NULL
);
CREATE TABLE IF NOT EXISTS Alerte(
idAlerte int(3) PRIMARY KEY AUTO_INCREMENT,
unite varchar(10) NOT NULL,
Max1 int(10) NOT NULL,
Max2 int(10) NOT NULL,
Max3 int(10) NOT NULL,
type boolean NOT NULL,
idPol int(3),
FOREIGN KEY (idPol) REFERENCES Polluant(idPol)
);
Here are entry's:
insert into polluant(nom,unite) values ("testPol","g/m3");
insert into alerte values (1,"test",1,2,3,true,1);
insert into alerte values (2,"autretest",2,4,40,false,1); !! this one isn't OK
currently trying on mysql but it will go on sqllite asap.
i add a entry in the Polluant table, with id=1.
i add a entry in the Alerte table, with idPol =1. no problem.
i add a second entry in the Alerte table , with idPol = 1 . MySQL happily tell me :
1062 - Duplicate entry '1' for key 'idPol'
mhhhh. Why ? it have to be unique in the table polluant ofc and it is, but it doesn't have to be in Alerte, do it? Well , i don't understand the problème, it look fine for me. Do somebody have an idea?
Thinqs