Cannot delete or update a parent row: a foreign key constraint fails. MagicDraw tables error

42
March 01, 2019, at 6:20 PM

I have an assignment where I have to make tables in MagicDraw and then to generate MySQL code. I pasted the generated code to SQL code section in phpMyAdmin and it showed an error:

SQL query:

DROP TABLE IF EXISTS LogistikosCentras;

MySQL answer:

#1217 - Cannot delete or update a parent row: a foreign key constraint fails

These are my tables:

And this is some of my code:

CREATE TABLE LogistikosCentras
(
    pavadinimas varchar (255) NOT NULL,
    adresas varchar (255) NOT NULL,
    telefonas int NOT NULL,
    el_pastas varchar (255) NOT NULL,
    id_LogistikosCentras integer NOT NULL,
    PRIMARY KEY(id_LogistikosCentras)
);
CREATE TABLE SiuntosPervezimoTarnyba
(
    pavadinimas varchar (255) NOT NULL,
    transportoPriemonesTalpa double precision NOT NULL,
    transportoPriemoniuKiekis int NOT NULL,
    transportoPriemone varchar (15) NOT NULL,
    pristatymoGreitis varchar (8) NOT NULL,
    id_SiuntosPervezimoTarnyba integer NOT NULL,
    CHECK(transportoPriemone in ('sunkvezimis', 'laivas', 'lektuvas', 
'lengvojiMasina')),
    CHECK(pristatymoGreitis in ('valandos', 'dienos')),
    PRIMARY KEY(id_SiuntosPervezimoTarnyba)
);
CREATE TABLE Darbuotojas
(
    vardas varchar (255) NOT NULL,
    pavarde varchar (255) NOT NULL,
    tabelio_nr char (255) NOT NULL,
    pareigos char (10) NOT NULL,
    id_Darbuotojas integer NOT NULL,
    fk_LogistikosCentrasid_Logistikoscentras integer NOT NULL,
    CHECK(pareigos in ('buhalteris', 'krovejas')),
    PRIMARY KEY(id_Darbuotojas, fk_LogistikosCentrasid_Logistikoscentras),
    CONSTRAINT dirba FOREIGN KEY(fk_LogistikosCentrasid_Logistikoscentras) 
REFERENCES LogistikosCentras (id_LogistikosCentras)
);
READ ALSO
Retrieve column based on on secondary column all having same value

Retrieve column based on on secondary column all having same value

I have a table that holds schedule entry itemsIt has an ID which is the ID of a related schedule record and a VALUE which is a Y or N to indicate whether it is complete

47
Does a union ruin indexing in MySQL 5.6?

Does a union ruin indexing in MySQL 5.6?

A question on how MySQL works under the hoodSay I have two tables, table1, and table2_archive

25
How to escape double backticked value in csh command line

How to escape double backticked value in csh command line

In tcsh, I'm trying/failing to run this on the command line, a mysql invocation that runs a query

33
Knowing if a specific column exists or not

Knowing if a specific column exists or not

Hi, when entering the following url (for learning purpose only) I can see an image with id=1

47