I tried to delete the an entry from a table through http://localhost/phpmyadmin. It returned the following error :
"Cannot delete or update a parent row: a foreign key constraint fails (press
.prodstock
, CONSTRAINT fk_prodstock_prodlist1
FOREIGN KEY (item_code
) REFERENCES prodlist
(id
) ON DELETE NO ACTION ON UPDATE NO ACTION) "
I wrote a JAVA code to delete it from NetBeans :
private void loginBut46ActionPerformed(java.awt.event.ActionEvent evt) {
if (prodlist.getSelectedRowCount() == 0) {
JOptionPane.showMessageDialog(rootPane, "Select Raw to View!");
} else {
int r = prodlist.getSelectedRow();
String id = prodlist.getValueAt(r,0).toString();
String item_code = prodlist.getValueAt(r,1).toString();
try {
DB.DB.statement("delete from prodlist where id = '"+id+"' ");
DB.DB.statement("delete from prodstock where item_code='"+item_code+"'");
} catch (Exception ex) {
Logger.getLogger(Stock.class.getName()).log(Level.SEVERE, null, ex);
}
}
}