Hi all
Due to an issue with a larger project, I'm trying a basic test of using a MySQL database (using InnoDB engine), which is this:
I'm doing this using a typed DataSet within Visual Studio 2017 Community. My code is:
My error is:
MySql.Data.MySqlClient.MySqlException: 'Cannot add or update a child row: a foreign key constraint fails (`dbTest`.`tblOrders`, CONSTRAINT `FK_Orders_Customers` FOREIGN KEY (`CustomerID`) REFERENCES `tblCustomers` (`CustomerID`) ON DELETE CASCADE ON UPDATE CASCADE)'
The relation in MySQL is set to 'On Update CASCADE' and 'On Delete CASCADE' as shown:

Using SQL Server, this approach (assigning the ID of the PK to that of the FK works), so is it a MySQL thing?
Due to an issue with a larger project, I'm trying a basic test of using a MySQL database (using InnoDB engine), which is this:
- Add a new row to a 'Customers' table.
- Add a new row, at the same time, to an 'Orders' table.
I'm doing this using a typed DataSet within Visual Studio 2017 Community. My code is:
C#:
DataSet1 ds = new DataSet1(); DataSet1TableAdapters.TableAdapterManager manager = new DataSet1TableAdapters.TableAdapterManager();
manager.tblCustomersTableAdapter = new DataSet1TableAdapters.tblCustomersTableAdapter();
manager.tblCustomersTableAdapter.Fill(ds.tblCustomers);
manager.tblOrdersTableAdapter = new DataSet1TableAdapters.tblOrdersTableAdapter();
manager.tblOrdersTableAdapter.Fill(ds.tblOrders);
DataSet1.tblCustomersRow custRow = ds.tblCustomers.NewtblCustomersRow();
custRow.Name = "Berty";
ds.tblCustomers.Rows.Add(custRow);
DataSet1.tblOrdersRow ordersRow = ds.tblOrders.NewtblOrdersRow();
ordersRow.CustomerID = custRow.CustomerID;
ds.tblOrders.Rows.Add(ordersRow);
manager.UpdateAll(ds);
My error is:
MySql.Data.MySqlClient.MySqlException: 'Cannot add or update a child row: a foreign key constraint fails (`dbTest`.`tblOrders`, CONSTRAINT `FK_Orders_Customers` FOREIGN KEY (`CustomerID`) REFERENCES `tblCustomers` (`CustomerID`) ON DELETE CASCADE ON UPDATE CASCADE)'
The relation in MySQL is set to 'On Update CASCADE' and 'On Delete CASCADE' as shown:

Using SQL Server, this approach (assigning the ID of the PK to that of the FK works), so is it a MySQL thing?