phpadmin和表单上的外键问题 [英] Problem with foreign keys in phpadmin and on forms

查看:77
本文介绍了phpadmin和表单上的外键问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有三个表。所有三个都通过引用主表的外键绑定在一起。主表(CompanyData)具有主键(companyID)。两个子表(RepData和ContactData)各自具有引用主表主键的外键(ID_company)。



CompanyData拥有ContactData(OnetoOne),而CompanyData拥有RepData(OnetoMany)。



现在,我可以使用phpAdmin物理添加到每个表没有问题。但是,我不能通过表格来做到这一点。在我添加关系之前,表单正常工作并且很好。从那时起,我得到:



无法添加或更新子行:外键约束失败(`reviewmy_jos1``dataContact`,CONSTRAINT`FK_contactid_companyid` FOREIGN KEY(`id_company`)REFERENCES`dataCompany`(`companyID`)ON DELETE CASCADE ON UPDATE CASCADE)



我不明白,怎么办?插入数据时通过phpAdmin完美无缺,但通过表单插入时却没有?



另外,如果它有所作为我正在使用MariaDB。



我是什么尝试过:



在添加关系时插入数据时,插入数据时在phpAdmin中工作不起作用。

I have three tables in my database. All three are tied together by a foreign key referencing the main table. Main table (CompanyData) has primary key (companyID). Two child tables (RepData and ContactData) each have foreign keys (ID_company) that references the main table's primary key.

CompanyData owns ContactData (OnetoOne) and CompanyData owns RepData (OnetoMany).

Now, I can physically add to each table using phpAdmin with no problem. However, I can not do it through a form. The form is working and was just fine before I added the relationships. Since then, I get:

"Cannot add or update a child row: a foreign key constraint fails (`reviewmy_jos1`.`dataContact`, CONSTRAINT `FK_contactid_companyid` FOREIGN KEY (`id_company`) REFERENCES `dataCompany` (`companyID`) ON DELETE CASCADE ON UPDATE CASCADE) "

What I don't understand, how could it work perfectly fine through phpAdmin when inserting the data but not when inserted through the form?

Also, if it makes a difference I'm using MariaDB.

What I have tried:

Works in phpAdmin when inserting data does not work in form when inserting data since adding the relationships.

推荐答案

如果没有查看代码的好处,我只能假设您从表单中将数据插入表中的顺序不正确。



您不能将行添加到 RepData ,也不能 ContactData ,直到 ID_company CompanyData 表中存在(作为 companyID
Without the benefit of seeing your code, I can only assume that the order you are inserting data into the tables from the form is incorrect.

You cannot add rows to RepData nor ContactData until ID_company exists (as companyID) on the CompanyData table


这篇关于phpadmin和表单上的外键问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆