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 7191401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:43:17+00:00 2026-05-28T19:43:17+00:00

Good evening. For a project, I have to create a system. In this system,

  • 0

Good evening.

For a project, I have to create a system. In this system, users can subscribe for a masterclass. The administrator should be able to delete users and masterclasses, but the latter only if no users has subscribed to it.

My database:

CREATE TABLE IF NOT EXISTS Speler_masterclass  (
        Sid                INT(11)                NOT NULL         AUTO_INCREMENT,
        naam                VARCHAR(50)        NOT NULL,
adres                VARCHAR(100) NOT NULL,
postcode        VARCHAR(100) NOT NULL,
woonplaats        VARCHAR(100) NOT NULL,
telefoonnr        INT(20)                NOT NULL,
        email                VARCHAR(100)        NOT NULL,
        ratingscore        INT(11)                NOT NULL DEFAULT '0',


PRIMARY KEY(Sid)
)ENGINE=InnoDb;




CREATE TABLE IF NOT EXISTS db11071230.Masterclass (
                   Mid                        INT(11)                NOT NULL        AUTO_INCREMENT,
                   naam                        VARCHAR(50)        NOT NULL,
            tijd                        VARCHAR(20)        NOT NULL,
            datum                        VARCHAR(10)        NOT NULL,
            plaats                        VARCHAR(100)        NOT NULL,
            minimale_rating        INT(11)        NOT NULL,

PRIMARY KEY (Mid)
) ENGINE=InnoDb;

CREATE TABLE IF NOT EXISTS  db11071230.Geeft_masterclass (
            Rankingspunten_cadeau        INT(11)        NOT NULL,
            Sid                                 INT(11)        NOT NULL,
            Mid                                INT(11)           NOT NULL,

FOREIGN KEY (Sid)               REFERENCES Speler_masterclass (Sid),
FOREIGN KEY (Mid)             REFERENCES Masterclass (Mid),
PRIMARY KEY (Sid, Mid)
) ENGINE=InnoDb;

CREATE TABLE IF NOT EXISTS  db11071230.Inschrijving_masterclass (
            betaling                                    INT(1)                    NOT NULL,
            Sid                                              INT(11)        NOT NULL ,
            Mid                                            INT(11)        NOT NULL ,

FOREIGN KEY (Sid)               REFERENCES Speler_masterclass (Sid),
FOREIGN KEY (Mid)             REFERENCES Masterclass (Mid)
ON DELETE RESTRICT
ON UPDATE CASCADE,
PRIMARY KEY (Sid, Mid)


) ENGINE=InnoDb;

IN this, I want to insert the following:

INSERT INTO Geeft_masterclass
        VALUES (5, 1, 1)
;
INSERT INTO Geeft_masterclass
        VALUES (6, 2, 2)
;
INSERT INTO Geeft_masterclass
        VALUES (7, 2, 2)
;


INSERT INTO Inschrijving_masterclass
        VALUES (0, 1, 1)
;
INSERT INTO Inschrijving_masterclass
        VALUES (1, 2, 1)
;
INSERT INTO Inschrijving_masterclass
        VALUES (1, 3, 2)
;


INSERT INTO Masterclass
VALUES (1, 'Masterclass 1', '10.30 uur', '15-2-2012',' Den Haag', 10)
;
INSERT INTO Masterclass
VALUES (2, 'Masterclass 2', '11.30 uur', '16-2-2012',' Den Haag', 11)
;
INSERT INTO Masterclass
VALUES (3, 'Masterclass 3', '12.30 uur', '17-2-2012',' Den Haag', 12)
;


INSERT INTO Speler_masterclass
VALUES (1, 'Speler 1', 'Adres', 'postcode','Den Haag', '0612345678', 'email@adres.nl', 0)
;
INSERT INTO Speler_masterclass
VALUES (2, 'Speler 2', 'Adres', 'postcode','Den Haag', '0612345678', 'email@adres.nl', 0)
;
INSERT INTO Speler_masterclass
VALUES (3, 'Speler 3', 'Adres', 'postcode','Den Haag', '0612345678', 'email@adres.nl', 0)
;

HOWEVER, if I try to do so, I get the following error:

Error code: 1452. Cannot add or update a child row: a foreign key constraint fails.

I have not got a clue what I’m doing 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-28T19:43:18+00:00Added an answer on May 28, 2026 at 7:43 pm

    When you have foreign key references from one table (source) into another (target), you need to set up the data in that target table first.

    At the point where you’re inserting (for example) {5,1,1} into Geeft_masterclass (and those second and third column have foreign key constaints), there is no data in the Speler_masterclass or Masterclass tables, the two tables which are the targets for those constraints.

    Quick solution, populate the tables in the same order that you create them. Then the data should exist in the target tables which will allow the constraints to succeed in the source tables:

    • Speler_masterclass;
    • Masterclass;
    • Geeft_masterclass, references Speler_masterclass and Masterclass; and
    • Inschrijving_masterclass, references Speler_masterclass and Masterclass.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good evening, i need to know how can i have one .h file that
Good evening, I am tired and have been fighting with this for hours. I
Good evening :-)! I have this code to use Drag & Drop method for
Good Evening, I am pretty new to Unix so maybe this mini project is
Good evening, In my app that I'm currently developing, I have a class that
Good morning, afternoon, evening or night (depending on your timezone). This is just a
Good evening fellow coders, and thank you in advance for any help/attention. This is
Good evening guys, how can I run a piece of jQuery/ajax when a certain
Good evening I have a JTable that I built with a TableModel how to
Good Evening All, I've created the following stored procedure: CREATE PROCEDURE AddQuote -- Add

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.