Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4171212
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T00:25:14+00:00 2026-05-21T00:25:14+00:00

Trying to help an intern with her project. She wants to add foreign keys

  • 0

Trying to help an intern with her project. She wants to add foreign keys to an existing table but this query:

ALTER TABLE `document` 
  ADD CONSTRAINT `document_ibfk_1` FOREIGN KEY (`cle_author`) 
  REFERENCES `author` (`id_author`) 
  ON DELETE CASCADE 
  ON UPDATE CASCADE;

gives this error:

ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`wrc_mysql`.<result 2 when explaining filename '#sql-30e4_7000d'>, CONSTRAINT `document_ibfk_1` FOREIGN KEY (`cle_author`) REFERENCES `author` (`id_author`) ON DELETE CASCADE ON UPDATE CASCADE)

Schema are like so

CREATE TABLE `document` (
  `id_document` int(11) NOT NULL AUTO_INCREMENT,
  `abstract` text,
  `number_of_pages` int(10) DEFAULT NULL,
  `original_surrey_citation` varchar(255) DEFAULT NULL,
  `updated_citation` varchar(255) DEFAULT NULL,
  `library_of_congress` varchar(10) DEFAULT NULL,
  `cross_citation` varchar(50) DEFAULT NULL,
  `doc_type` varchar(255) DEFAULT NULL,
  `questions` varchar(255) DEFAULT NULL,
  `keywords` varchar(255) DEFAULT NULL,
  `cle_author` int(10) NOT NULL,
  PRIMARY KEY (`id_document`),
  KEY `cle_author` (`cle_author`)
) ENGINE=InnoDB AUTO_INCREMENT=22591 DEFAULT CHARSET=utf8

CREATE TABLE `author` (
  `id_author` int(10) NOT NULL AUTO_INCREMENT,
  `author_name` varchar(255) DEFAULT NULL,
  `sender_office` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id_author`),
  KEY `author_name` (`author_name`,`sender_office`)
) ENGINE=InnoDB AUTO_INCREMENT=22591 DEFAULT CHARSET=utf8

Anyone know what is going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T00:25:15+00:00Added an answer on May 21, 2026 at 12:25 am

    You probably have inconsistent data between your two tables. This error means that you have a cle_author value in your document table that doesn’t have a corresponding entry in the author table. Since the cle_author value is going to be set up as a foreign key, each value for that field must have a corresponding entry in the author table’s id_author field.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to help a friend with his project. The website has this <li>
I need help trying set-up Foreign Keys after having difficulty following Music library MySQL
I am trying to help a friend on a project of his, however it
I'm trying to help a friend in a college assignment, but i kind of
I need some help trying to come up with a way to set this
I am trying to help a co-worker with a peculiar problem, and she's limited
I'm trying to help my son solve a math problem. This seems like a
I need help trying to join a table that uses an association table. I
I'm trying to help debug a hang with the VS 2008 debugger. If I
I am trying to help a friend of mine break his site out of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.