![]() |
|
#1
|
|||
|
|||
|
Im designing a database to take care of tenders for a company, which told me to do it according to an erd they created (which sucks) so i did. By the way im not getting paid for this, its a school thing. So in this database we have a table tenderi and a table statuses which are 5 different statuses a tender can be in like not offering for this tender, offer made, contract made etc. So i made this web page form where u can insert a tender and where u choose a status from a drop down list which is gathered from the table statuses whose primary key, statusID is a name of the status since there are only 5 of em. Status ID is an enum value with 5 possible values. Ok so the mistake im getting is when i try to insert a tender. It tells me:
Could not execute query! Cannot add or update a child row: a foreign key constraint fails (`dino`.`tenderi`, CONSTRAINT `tenderi_ibfk_4` FOREIGN KEY (`Status`) REFERENCES `status` (`StatusID`)) So far so familiar u think right? Well here's where it gets weird, if from the drop down list i choose a value of status called 'offered' it works, it inputs it into the database like everything is hunky dory, but if i choose any other value it gives me that mistake, I even tried deleting the table statuses and building it again, still the same, when i changed the table offered to be something else like tender offered it didnt work, for some reason it works only when the value is 'offered' but i have no idea why, as its not specified as anywhere in my code which is like this for statuses. This is what the show InnoDB status told me about my error CONSTRAINT `FK_tenderi_status` FOREIGN KEY (`Status`) REFERENCES `statusi` (`StatusID`) Trying to add in child table, in index `IndexStatus` tuple: DATA TUPLE: 2 fields; 0: len 1; hex 00; asc ;; 1: len 2; hex 002e; asc .;; But in parent table `dino`.'statusi', in index `IndexStatusID`, the closest match we can find is record: PHYSICAL RECORD: n_fields 2; compact format; info bits 0 0: len 1; hex 01; asc ;; 1: len 6; hex 00000000060b; asc ;; 2: Just to clarify, both tables are InnoDB both columns are of the same enum values and both are indexes (although i tried it with makin StatusID a primary key and makin both or one of them unique). I also did the show create table and here are the results for further information This is for the table Tenderi CREATE TABLE `tenderi` ( `TenderID` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `RedniBroj` smallint(5) unsigned NOT NULL, `BrProtTend` varchar(50) NOT NULL, `ImeTendera` varchar(100) NOT NULL, `Predmet` varchar(255) DEFAULT NULL, `DatumLicitacije` date DEFAULT NULL, `PosebniKriteriji` varchar(255) DEFAULT NULL, `UsloviPlacanja` varchar(255) DEFAULT NULL, `ProcjenaVrijednosti` float DEFAULT NULL, `LicitacionaGarancija` float DEFAULT NULL, `OpcijaLG` varchar(2) DEFAULT NULL, `Valuta` enum('KM','$','EUR') DEFAULT NULL, `Paritet` float DEFAULT NULL, `Lokacija` varchar(255) DEFAULT NULL, `IzvedGaranc` float DEFAULT NULL, `AvansnaGarancija` float DEFAULT NULL, `KomitentID` smallint(6) DEFAULT NULL, `Drzavaid` enum('BIH','USA','HRV','SRB','SLO') DEFAULT NULL, `InvestitorID` smallint(6) DEFAULT NULL, `NosiocPoslaID` varchar(50) DEFAULT NULL, `OstaliUcesnici` varchar(255) DEFAULT NULL, `Telefon` varchar(50) DEFAULT NULL, `Kontakt` varchar(200) DEFAULT NULL, `Zapisano` datetime DEFAULT NULL, `Promjena` datetime DEFAULT NULL, `RatingTendera` enum('1','2','3','4','5') NOT NULL, `Odlozeno` varchar(50) DEFAULT NULL, `Status` enum('ponudjen','ne nuditi','isteko rok','ponuda prihvacena','sklopljen ugovor') DEFAULT NULL, PRIMARY KEY (`TenderID`), UNIQUE KEY `RedniBroj` (`RedniBroj`), KEY `NosiocPoslaID` (`NosiocPoslaID`), KEY `Valuta` (`Valuta`), KEY `FK_tenderi` (`KomitentID`), KEY `IndexStatus` (`Status`), CONSTRAINT `FK_tenderi` FOREIGN KEY (`KomitentID`) REFERENCES `komitenti` (`KomitentID`), CONSTRAINT `FK_tenderi_status` FOREIGN KEY (`Status`) REFERENCES `statusi` (`StatusID`), CONSTRAINT `tenderi_ibfk_1` FOREIGN KEY (`NosiocPoslaID`) REFERENCES `nosiocposla` (`NosiocPoslaID`), CONSTRAINT `tenderi_ibfk_3` FOREIGN KEY (`Valuta`) REFERENCES `kursnalista` (`ValutaID`) ) ENGINE=InnoDB AUTO_INCREMENT=45 DEFAULT CHARSET=latin1 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC And here is the create show table statusi CREATE TABLE `statusi` ( `StatusID` enum('ponudjen','ne nuditi','isteko rok','ponuda prihvacena','sklopljen ugovor') NOT NULL, `Namjena` varchar(50) DEFAULT NULL, KEY `IndexStatusID` (`StatusID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC I also did the show insert form so here is the one where i choose the value 'offered' (ponudjeni) which works perfectly. INSERT INTO tenderi (RedniBroj, BrProtTend, ImeTendera, DatumLicitacije, PosebniKriteriji, ProcjenaVrijednosti, Predmet, LicitacionaGarancija, IzvedGaranc, Kontakt, Odlozeno, OpcijaLG, AvansnaGarancija, Telefon, Valuta, Drzavaid, Status, NosiocPoslaID, KomitentID) VALUES ('6','2','','','','','','','','','','','','','KM','BIH','ponudjen ','Adi', '34') Redni Broj BrProtTend ImeTendera Datum Licitacije Posebni Kriteriji Procijenjena Vrijednosti Predmet Tendera Licitaciona Garancija Izvedbena Garancija Kontakt Odlozeno Opcija Licitacione Garancije Avansna Garancija Telefon Komitent Investitor Nosioc Posla 6 2 Sve u databazi Redni Broj BrProtTend ImeTendera Datum Licitacije Posebni Kriteriji Procijenjena Vrijednosti Predmet Tendera Licitaciona Garancija Izvedbena Garancija Kontakt Odlozeno Opcija Licitacione Garancije Avansna Garancija Telefon Komitent 42 160 231234 bla dsadas 2009-06-23 dsasasda 43243 432 Da KM 432423 2143 34 SLO Dino.Kantardzic 061488375 bladfg 1 dhsajad ponudjen 44 1 0000-00-00 0 0 KM 0 0 34 BIH Adi 1 ponudjen 45 5 2 0000-00-00 0 0 KM 0 0 34 BIH Adi 1 ponudjen 48 6 2 0000-00-00 0 0 KM 0 0 34 BIH Adi And this is what happens when it doesn't work, which is for any other value INSERT INTO tenderi (RedniBroj, BrProtTend, ImeTendera, DatumLicitacije, PosebniKriteriji, ProcjenaVrijednosti, Predmet, LicitacionaGarancija, IzvedGaranc, Kontakt, Odlozeno, OpcijaLG, AvansnaGarancija, Telefon, Valuta, Drzavaid, Status, NosiocPoslaID, KomitentID) VALUES ('7','2','','','','','','','','','','','','','KM','BIH','ne','Adi ', '34') Could not execute query! Cannot add or update a child row: a foreign key constraint fails (`dino`.`tenderi`, CONSTRAINT `FK_tenderi_status` FOREIGN KEY (`Status`) REFERENCES `statusi` (`StatusID`)) Redni Broj BrProtTend ImeTendera Datum Licitacije Posebni Kriteriji Procijenjena Vrijednosti Predmet Tendera Licitaciona Garancija Izvedbena Garancija Kontakt Odlozeno Opcija Licitacione Garancije Avansna Garancija Telefon Komitent Investitor Nosioc Posla 7 2 Sorry for the long post, I just wanted to give u guys all the information as soon as possible because i really need your help, I am at my wits end, so if anyone has any idea as to what might be a problem, I will be eternally gratefull. Thanks In Advance
__________________
Life\'s a bitch.... ...and i\'m its Pimp |
|
|
|||
|
|||
|
|
| Thread Tools | |
| Display Modes | |
|
|