Searched through the forums, tried a bunch of solutions, but nothing seems to be working. Below is a small snippet of the code and the online compiler I used.
I get (errno: 150 "Foreign Key constraint is incorrectly formed"). Do note, this error appears through out all of the tables in the code, whenever I try to add a foreign key.
Online Complier: https://paiza.io/en/languages/mysql
Code:
-- CREATING AND INSERTING VALUES INTO THE BOOKINGS TABLE WITHOUT FK--
create table Bookings(
Booking_ID varchar(9) NOT NULL,
Client_ID varchar(6) NOT NULL,
PT_ID varchar(4) NOT NULL,
Booking_Date Date NOT NULL,
Start_Time time NOT NULL,
End_Time time NOT NULL,
Focus_ID varchar(3) NOT NULL,
Staff_ID varchar(4) NOT NULL,
PRIMARY KEY (Booking_ID)
);
INSERT INTO Bookings
VALUES
('B00000001','C00001','T001','2020-01-1','19:30:00','20:15:00','F01','S002'),
('B00000002','C00023','T001','2020-01-1','09:00:00','09:30:00','F02','S001'),
('B00000007','C00156','T003','2020-01-1','10:00:00','11:00:00','F04','S003');
-- CREATING AND INSERTING VALUES INTO THE CLIENT TABLE --
create table Client(
Client_ID varchar(6) NOT NULL,
Client_Name varchar(20) NOT NULL,
Height_cm decimal(5,2) NOT NULL,
Weight_kg decimal(6,2) NOT NULL,
Ph_Num varchar(14) NOT NULL,
PRIMARY KEY (Client_ID),
FOREIGN KEY (Client_ID)
REFERENCES Bookings(Client_ID)
);
-- ALTERING BOOKINGS TABLE WITH FOREIGN KEYS --
ALTER TABLE Bookings
ADD
FOREIGN KEY (Client_ID)
REFERENCES Client(Client_ID);
As I mentioned in the title, the code works fine online, but fails when compiled via MariaDB on Linux Terminal.
MariaDB Server Version is 10.3.17-MariaDB
What am I doing wrong? any help would be greatly appreciated.