Salve sto usando java con eclipse integrando MySql. Ho nua tabella utenti (docenti) e una tabella ricevimenti:
Ho fatto la query di inserimento per aggiungere un nuovo ricevimento per un determinato docente:codice:create table if not exists Utenti( ID int not null auto_increment, Nome_utente varchar(30) not null, Password varchar(10) not null, Cognome char(30), Nome char(30), Email varchar(30), Telefono varchar(15), Fax varchar(15), Dipartimento char(30), Pagina_web varchar(70), Ufficio varchar(10), Tipo set('false','true') default 'false', primary key (ID)); create table if not exists Ricevimento( ID int not null auto_increment, Docente int not null default '0', Giorno char(10), Orario_Inizio time, Orario_Fine time, Dipartimento char(30), Piano varchar(10), Stanza int(3), primary key(ID), foreign key (Docente) references Utenti(ID));
ed ho avuto il seguente errore:codice:INSERT INTO Ricevimento VALUES ('2', 'lun', '10:00:00', '11:00:00', 'Math', 'terzo', '23');
com.mysql.jdbc.exceptions.MySQLIntegrityConstraint ViolationException: Cannot add or update a child row: a foreign key constraint fails (`db_schedule/ricevimento`, CONSTRAINT `Ricevimento_ibfk_1` FOREIGN KEY (`Docente`) REFERENCES `utenti` (`ID`))
cosa dovrei fare? da quel che ho capito non ho fatto errori di sintassi, ma un errore nel database..
aiuto!

Rispondi quotando

