473,657 Members | 2,266 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cannot add or update a child row

2 New Member
Please help,I'm very frustated.

when I ADD
the data in kn_history_ques tion table of htbase_tst database....it giving the error "Cannot add or update a child row:a foreign key constraint fails,<'htbase_ tst/kn_history_ques tion', CONSTRAINT 'FK_kn_history_ question_compla int' FOREIGN KEY ('complaint_id' ) REFERENCES 'complaint'('id ')).

This is my table script.....

CREATE TABLE `city` (
`id` int(11) NOT NULL auto_increment,
`city_name` varchar(255) default NULL,
`city_code` varchar(80) default NULL,
`state_id` int(11) default NULL,
`Nearest_airpor t_code` varchar(80) default NULL,
`date_updated` timestamp NULL default NULL,
`date_created` timestamp NULL default NULL,
PRIMARY KEY (`id`),
KEY `FK_cities_stat es` (`state_id`)
) ENGINE=MyISAM AUTO_INCREMENT= 11 DEFAULT CHARSET=utf8;


CREATE TABLE `kn_history_que stion` (
`id` int(11) NOT NULL auto_increment,
`complaint_id` int(11) default NULL,
`question_text` varchar(255) default NULL,
`sex_relevance` varchar(20) default NULL,
`age_group_rele vance` varchar(255) default NULL,
`date_created` timestamp NOT NULL default CURRENT_TIMESTA MP on update CURRENT_TIMESTA MP,
`date_updated` timestamp NOT NULL default '0000-00-00 00:00:00',
`count_of_respo nses` int(5) default NULL COMMENT ', paint radio buttons if value is one else check boxes',
`doctor_id` int(11) default NULL,
PRIMARY KEY (`id`),
KEY `FK_kn_history_ question_compla int` (`complaint_id` ),
CONSTRAINT `FK_kn_history_ question_compla int` FOREIGN KEY (`complaint_id` ) REFERENCES `complaint` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


ERROR:"Cannot add or update a child row:a foreign key constraint fails,<'htbase_ tst/kn_history_ques tion', CONSTRAINT 'FK_kn_history_ question_compla int' FOREIGN KEY ('complaint_id' ) REFERENCES 'complaint'('id ')).

Please give the solution of this ERROR.
Jul 8 '07 #1
1 5960
dafodil
392 Contributor
Some row in the child does not comply with the constraint, correct the problem.
You find the rows like this:
select child.id from child left join parent on (child.parent_i d=parent.id) where child.id is not null and parent.id is null;
Jul 9 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
36251
by: Ralph Smith | last post by:
I'm having trouble copying a database to another machine. Here are the two table's in ths database and the sql commands: DROP TABLE IF EXISTS `clients`; CREATE TABLE `clients` ( `client_id` int(10) unsigned NOT NULL auto_increment, `lastname` char(15) NOT NULL default '', `firstname` char(15) NOT NULL default '', `birthdate` date NOT NULL default '0000-00-00',
3
7507
by: Fabio Negri Cicotti [MCP] | last post by:
Hi All. I'm trying to insert data into 2 tables (parent-child) using the ADO.NET's SetParentRow method. The parent table has an identity column as primary key. When I execute the code below I get the following message: "Cannot insert the value NULL into column 'hdtID', table 'myinstance.mydb.Hotel_Details_Lang'; column does not allow nulls. INSERT fails." Any idea? PS: To create the DataAdapters, I'm using SqlCommandBuilder.
6
10666
by: Aaron Smith | last post by:
Ok. I have a dataset that has multiple tables in it. In one of the child tables, I have a column that I added to the DataSet (Not in the DataSource). This column does not need to be stored in the data on the datasource. It simply gets the first name and last name of an instructor and displays it in the grid. I have two major problems.... One, it doesn't display in the column until the row is saved, (Even after calling a refresh on the...
5
3531
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I do the update the changed parentid in the child table fails to change. No error is given its just that the change is not written to the Database. When I step through the records for the child table the one I would expect to be changed has a row...
3
5436
by: fuimens | last post by:
Hi, With mysql-4.0.20, I have a problem inserting data with foreign key references, MySQL saying ERROR 1216: Cannot add or update a child row: a foreign key constraint fails The message is confusing because a parent record in parent table exists !? The "show innodb status; " command prints :
1
2767
by: Hexman | last post by:
Hello All, What I'm trying to do is update a child record using a parent-child relation. I want to find out if it is faster than than doing multiple selects. Anyways, I've created a dataset (ds), have 2 datatables (dtRC and dtST). Created the parent-child relationship with multiple columns and added the relation to the dataset. Now what I want is to move through each of the dtRC (parent) records, get all related dtST (child) records...
13
6560
by: dennis | last post by:
Hello, I'm having trouble solving the following problem with DB2 UDB 8.2. I need to create a trigger that performs certain extra constraint validations (temporal uniqueness). One of the tables has no primary key. I'm having trouble expressing an update trigger that checks for existing rows, contemporary to the updated one, but exclusing the
4
5037
by: Ryan | last post by:
I've got a little bit of code that runs when you enter data in a datasheet view (which is a subform of the form you are in) if rst!DateReceived >= 30 Then Forms!DisposalRecords.Label90.Caption = (Date - rst!DateReceived) & " Days" however, when that runs to update the caption, it says that it cannot find form DisposalRecords
0
3158
by: Pete Newman | last post by:
In running vs (vb ) .net 2005 and Sql 2005 On my form i have an oledbconnection, an oledbdataadapter and a dataset. when i try and do an update i get an error; 'Child list for field DebBacsfmDestAccs cannot be created' im at a loss as to how to resolve this .. i need help please code;
0
8407
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8319
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8837
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8612
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7347
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
2739
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.