SQL Management Studio - Database Diagram does not show every table created - mysql

So I have created a database which looks like that.
CREATE TABLE Budova
(
BudovaID int primary key not null,
BytyPocet int not null,
);
CREATE TABLE Skupina
(
SkupinaID int primary key not null,
NajemniciPocet int not null,
BytID int not null,
FOREIGN KEY (BytID) REFERENCES Byt(BytID) ON DELETE CASCADE,
);
CREATE TABLE Najemnici
(
NajemnikID int primary key not null,
Jmeno varchar(255) null,
Prijmeni varchar(255) null,
Vek int null,
SkupinaID int not null,
BytID int not null,
CenaEnergii int not null,
FOREIGN KEY (BytID) REFERENCES Byt(BytID),
FOREIGN KEY (SkupinaID) REFERENCES Skupina(SkupinaID)
);
CREATE TABLE Byt
(
BytID int primary key not null,
BudovaID int not null,
OpravaID int not null,
FOREIGN KEY (BudovaID) REFERENCES Budova(BudovaID) ON DELETE CASCADE,
FOREIGN KEY (OpravaID) REFERENCES Opravy(OpravaID) ON DELETE CASCADE
);
CREATE TABLE Vydaje
(
BytID int not null,
Voda int not null,
Elektrina int not null,
Plyn int not null,
Zaloha int not null,
Celkem int not null,
CelkemEura int not null
FOREIGN KEY (BytID) REFERENCES Byt(BytID)
);
CREATE TABLE Opravy
(
OpravaID int primary key not null,
OpravaTyp varchar(255) not null,
OpravaCena int not null,
);
I have basically 6 tables in the database but when I've tried to create database diagram, it haven't shown every single table.
As you can see, it shows only 5 of them.
At the end, it looks like that.
I've tried to change the references, but It went literally to hell. Do you know, what I should do to make it works?

You have a lot some errors on your statementm regardkless which dbms you use.
Try this create query in that order it is posted, or else the foreign keys won't work
CREATE TABLE Budova
(
BudovaID int primary key not null,
BytyPocet int not null
);
CREATE TABLE Opravy
(
OpravaID int primary key not null,
OpravaTyp varchar(255) not null,
OpravaCena int not null
);
CREATE TABLE Byt
(
BytID int primary key not null,
BudovaID int not null,
OpravaID int not null,
FOREIGN KEY (BudovaID) REFERENCES Budova(BudovaID) ON DELETE CASCADE,
FOREIGN KEY (OpravaID) REFERENCES Opravy(OpravaID) ON DELETE CASCADE
);
CREATE TABLE Skupina
(
SkupinaID int primary key not null,
NajemniciPocet int not null,
BytID int not null,
FOREIGN KEY (BytID) REFERENCES Byt(BytID) ON DELETE CASCADE
);
CREATE TABLE Najemnici
(
NajemnikID int primary key not null,
Jmeno varchar(255) null,
Prijmeni varchar(255) null,
Vek int null,
SkupinaID int not null,
BytID int not null,
CenaEnergii int not null,
FOREIGN KEY (BytID) REFERENCES Byt(BytID),
FOREIGN KEY (SkupinaID) REFERENCES Skupina(SkupinaID)
);
CREATE TABLE Vydaje
(
BytID int not null,
Voda int not null,
Elektrina int not null,
Plyn int not null,
Zaloha int not null,
Celkem int not null,
CelkemEura int not null,
FOREIGN KEY (BytID) REFERENCES Byt(BytID)
);

Related

MySQL ERROR 1005 : Can't create table (errno: 150)

Im a beginner in mysql, i don't understand my mistake
its a problem with the foreign key of "membre" and "club".
CREATE TABLE club(
id INT PRIMARY KEY AUTO_INCREMENT,
nom VARCHAR(255) UNIQUE NOT NULL,
INDEX club_nom_index (nom),
adresse_id INT NOT NULL,
nom_du_responsable VARCHAR(255) NULL,
FOREIGN KEY club_adresse_id_fk (adresse_id) REFERENCES adresse(id)
);
CREATE TABLE membre(
id INT PRIMARY KEY AUTO_INCREMENT,
nom VARCHAR(255) NOT NULL,
prénom VARCHAR(255) NOT NULL,
adresse_id INT NOT NULL,
club_id INT NOT NULL,
rang_qualification INT NOT NULL,
numéro_téléphone VARCHAR(255) NULL,
courriel VARCHAR(255) UNIQUE NULL,
INDEX membre_courriel_index (courriel),
nb_parties_gagnées INT NOT NULL,
nb_parties_perdues INT NOT NULL,
nb_parties_nulles INT NOT NULL,
FOREIGN KEY membre_adresse_id_fk (adresse_id) REFERENCES adresse(id),
FOREIGN KEY membre_club_id_fk (club_id) REFERENCES club(id),
FOREIGN KEY membre_rang_qualification_fk (rang_qualification) REFERENCES rang(qualification),
INDEX nom_prénom_membre_index (nom, prénom),
CONSTRAINT parties_gagnées_chk CHECK (nb_parties_gagnées >= 0),
CONSTRAINT parties_perdues_chk CHECK (nb_parties_perdues >= 0),
CONSTRAINT parties_nulles_chk CHECK(nb_parties_nulles >= 0)
);
CREATE TABLE tournoi(
id INT PRIMARY KEY AUTO_INCREMENT,
nom VARCHAR(255) NOT NULL,
INDEX tournoi_nom_index (nom),
club_id INT NOT NULL,
date_début DATE NOT NULL,
date_fin DATE NOT NULL,
FOREIGN KEY tournoi_club_id_fk (club_id) REFERENCES club(id),
CONSTRAINT nom_date_unq UNIQUE (nom, date_début)
);
CREATE TABLE partie(
id INT PRIMARY KEY AUTO_INCREMENT,
membre1_id INT NOT NULL,
membre2_id INT NOT NULL,
résultat INT NULL,
date_début DATE NULL,
heure_début TIME NULL,
id_tournoi INT NOT NULL,
FOREIGN KEY partie_membre1_id_fk (membre1_id) REFERENCES membre(id),
FOREIGN KEY partie_membre2_id_fk (membre2_id) REFERENCES membre(id),
FOREIGN KEY partie_tournoi_id_fk (id_tournoi) REFERENCES tournoi(id),
INDEX membres_index(membre1_id, membre2_id),
CONSTRAINT résultat_chk CHECK (résultat >= 0 AND résultat <= 2),
CONSTRAINT membres_unq UNIQUE (membre1_id, membre2_id),
CONSTRAINT date_heure_unq UNIQUE (date_début, heure_début)
);
CREATE TABLE adresse(
id INT PRIMARY KEY AUTO_INCREMENT,
adresse VARCHAR(255) NOT NULL,
rue VARCHAR(255) NOT NULL,
ville VARCHAR(255) NOT NULL,
code_postal CHAR(6) NULL,
INDEX adresse_code_index (code_postal),
province_état CHAR(3) NULL,
pays CHAR(2) NOT NULL,
CONSTRAINT code_postal_chk CHECK (code_postal REGEXP '^[A-Z]
[[:digit:]][A-Z][[:digit:]][A-Z][[:digit:]]$')
);
CREATE TABLE rang(
qualification INT PRIMARY KEY AUTO_INCREMENT,
description VARCHAR(255) UNIQUE NULL
);
I was expecting the program to run but it keeps telling me that there is a problem with the foreign key in "membre" and "club".
You must change the order of the create statements.
First table rang and second table adresse, because the other tables have references to these tables:
CREATE TABLE rang(
qualification INT PRIMARY KEY AUTO_INCREMENT,
description VARCHAR(255) UNIQUE NULL
);
CREATE TABLE adresse(
id INT PRIMARY KEY AUTO_INCREMENT,
adresse VARCHAR(255) NOT NULL,
rue VARCHAR(255) NOT NULL,
ville VARCHAR(255) NOT NULL,
code_postal CHAR(6) NULL,
INDEX adresse_code_index (code_postal),
province_état CHAR(3) NULL,
pays CHAR(2) NOT NULL,
CONSTRAINT code_postal_chk CHECK (code_postal REGEXP '^[A-Z]
[[:digit:]][A-Z][[:digit:]][A-Z][[:digit:]]$')
);
CREATE TABLE club(
id INT PRIMARY KEY AUTO_INCREMENT,
nom VARCHAR(255) UNIQUE NOT NULL,
INDEX club_nom_index (nom),
adresse_id INT NOT NULL,
nom_du_responsable VARCHAR(255) NULL,
FOREIGN KEY club_adresse_id_fk (adresse_id) REFERENCES adresse(id)
);
CREATE TABLE membre(
id INT PRIMARY KEY AUTO_INCREMENT,
nom VARCHAR(255) NOT NULL,
prénom VARCHAR(255) NOT NULL,
adresse_id INT NOT NULL,
club_id INT NOT NULL,
rang_qualification INT NOT NULL,
numéro_téléphone VARCHAR(255) NULL,
courriel VARCHAR(255) UNIQUE NULL,
INDEX membre_courriel_index (courriel),
nb_parties_gagnées INT NOT NULL,
nb_parties_perdues INT NOT NULL,
nb_parties_nulles INT NOT NULL,
FOREIGN KEY membre_adresse_id_fk (adresse_id) REFERENCES adresse(id),
FOREIGN KEY membre_club_id_fk (club_id) REFERENCES club(id),
FOREIGN KEY membre_rang_qualification_fk (rang_qualification) REFERENCES rang(qualification),
INDEX nom_prénom_membre_index (nom, prénom),
CONSTRAINT parties_gagnées_chk CHECK (nb_parties_gagnées >= 0),
CONSTRAINT parties_perdues_chk CHECK (nb_parties_perdues >= 0),
CONSTRAINT parties_nulles_chk CHECK(nb_parties_nulles >= 0)
);
CREATE TABLE tournoi(
id INT PRIMARY KEY AUTO_INCREMENT,
nom VARCHAR(255) NOT NULL,
INDEX tournoi_nom_index (nom),
club_id INT NOT NULL,
date_début DATE NOT NULL,
date_fin DATE NOT NULL,
FOREIGN KEY tournoi_club_id_fk (club_id) REFERENCES club(id),
CONSTRAINT nom_date_unq UNIQUE (nom, date_début)
);
CREATE TABLE partie(
id INT PRIMARY KEY AUTO_INCREMENT,
membre1_id INT NOT NULL,
membre2_id INT NOT NULL,
résultat INT NULL,
date_début DATE NULL,
heure_début TIME NULL,
id_tournoi INT NOT NULL,
FOREIGN KEY partie_membre1_id_fk (membre1_id) REFERENCES membre(id),
FOREIGN KEY partie_membre2_id_fk (membre2_id) REFERENCES membre(id),
FOREIGN KEY partie_tournoi_id_fk (id_tournoi) REFERENCES tournoi(id),
INDEX membres_index(membre1_id, membre2_id),
CONSTRAINT résultat_chk CHECK (résultat >= 0 AND résultat <= 2),
CONSTRAINT membres_unq UNIQUE (membre1_id, membre2_id),
CONSTRAINT date_heure_unq UNIQUE (date_début, heure_début)
);

MySQL error:1251 cannot add foreign key

The first 4 table are created fine, the transactions tables run into problem. I get the 1215 error: cannot add foreign key. I've checked an rechecked the data types, and made sure all FK are PK of their own tables. What's wrong here?
CREATE SCHEMA FinalDB;
CREATE TABLE `User` (
userId int not null auto_increment primary key,
first_name varchar(255) not null,
last_name varchar(255) not null,
address varchar(255) null,
DOB date not null,
availableBalance int not null default 0,
currency varchar(20)
);
CREATE TABLE Verifications(
userId int not null primary key,
passport int null,
ssn int null,
license int null,
constraint
foreign key (userId)
references User(userId)
);
CREATE TABLE Linked_Account(
account_Id int not null,
userId int not null,
routing int null,
swift int null,
primary key (userId, account_Id),
constraint
foreign key (userId)
references User(userId)
);
CREATE TABLE Wallet (
userId int not null,
walletId varchar(5) not null,
coinAmount int not null default 0,
netWorth int not null default 0,
primary key(userId, walletId),
constraint
foreign key (userId)
references `User`(userId)
);
CREATE TABLE Transactions (
transactionId int not null primary key auto_increment,
userId int not null,
type varchar(30) not null,
walletId varchar(5) not null,
payment_method int null, #optional
total int null, #optional
quantity int not null,
fee int null, #optional
`date` date not null,
sender varchar(50) null, #optional
reciever varchar(50) null, #optional
status varchar(20) not null,
notes varchar(200) null, #optional
constraint
foreign key (userId)
references `User`(userId)
ON DELETE CASCADE ON UPDATE CASCADE,
constraint
foreign key (walletId)
references Wallet(walletId)
ON DELETE CASCADE ON UPDATE CASCADE,
constraint
foreign key (payment_method)
references Linked_Account(account_id)
);
CREATE TABLE TransactionsExchange(
transactionId int not null auto_increment primary key,
userId int not null,
currencyFrom int not null,
currencyFromAmount int not null,
currencyInto int not null,
currencyIntoEquivalent int not null,
notes varchar(200) null,
`date` date not null,
constraint
foreign key (userId)
references User(userId),
constraint
foreign key (currencyFrom)
references Wallet(walletId),
constraint
foreign key (currencyInto)
references Wallet(walletId)
);
I've look online for possible answer, but it's usually having to do with inconsistent data types or undeclared PK's. I'm basically trying to make a transactions table to log various different data in different compositions. Using backend logic to handle what is required and what is not, aside from a few defaults.
To use a compound Primary Key as Foreign Key, you'll have to add the
same number of columns (that compose the PK) with same datatypes to
the child table and then use the combination of these columns in the
FOREIGN KEY definition.
see related post here https://stackoverflow.com/a/10566463/4904726
Try this 'Transactions' table creating query:
CREATE TABLE Transactions (
transactionId int not null primary key auto_increment,
userId int not null,
type varchar(30) not null,
walletId varchar(5) not null,
payment_method int null, #optional
total int null, #optional
quantity int not null,
fee int null, #optional
`date` date not null,
sender varchar(50) null, #optional
reciever varchar(50) null, #optional
status varchar(20) not null,
notes varchar(200) null, #optional
constraint
foreign key (userId)
references `User`(userId)
ON DELETE CASCADE ON UPDATE CASCADE,
constraint
foreign key (userId, walletId)
references Wallet(userId, walletId)
ON DELETE CASCADE ON UPDATE CASCADE,
constraint
foreign key (userId, payment_method)
references Linked_Account(userId, account_id)
);

MySQL error code 1005 / errno: 150

I'm using a XAMPP 5.6.19-0 as a MySQL Database server and managing via MySQL Workbench (Mac OS 10.11.3). I'm trying to create some tables, with foreign keys, and im getting this error:
Error Code: 1005. Can't create table imobiliaria24h.proprietario (errno: 150 "Foreign key constraint is incorrectly formed")
This is the code I'm trying to use:
CREATE TABLE IF NOT EXISTS PROPRIETARIO (
NOME VARCHAR(30) NOT NULL,
CPF INT NOT NULL,
TELEFONE INT NOT NULL,
CORRETOR_CPF INT NOT NULL,
PRIMARY KEY (CPF),
FOREIGN KEY (CORRETOR_CPF) REFERENCES CORRETOR(CPF)
)ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS IMOVEL(
ENDERECO VARCHAR(100) NOT NULL,
TIPO ENUM('ALUGUEL', 'VENDA'),
INQUILINO_CPF INT,
PROPRIETARIO_CPF INT,
VALOR_ALUGUEL_PRECOVENDA INT NOT NULL,
NUM_QUARTOS INT NOT NULL,
METRAGEM INT NOT NULL,
NUM_BANHEIROS INT NOT NULL,
VALOR_CONDOMINIO INT NOT NULL,
IDADE INT NOT NULL,
HORA_REGISTRO TIME NOT NULL,
PRIMARY KEY(ENDERECO),
FOREIGN KEY (INQUILINO_CPF) REFERENCES INQUILINO(CPF),
FOREIGN KEY (PROPRIETARIO_CPF) REFERENCES PROPRIETARIO(CPF)
)ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS INQUILINO(
NOME VARCHAR(30) NOT NULL,
CPF INT NOT NULL,
TELEFONE INT NOT NULL,
FIADOR BOOLEAN NOT NULL,
INADIMPLENCIA INT NOT NULL,
CORRETOR_CPF INT NOT NULL,
PRIMARY KEY (CPF),
FOREIGN KEY (CORRETOR_CPF) REFERENCES CORRETOR(CPF)
)ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS CORRETOR(
NOME VARCHAR(30) NOT NULL,
CPF INT NOT NULL,
TELEFONE INT NOT NULL,
ANOS_CASA SMALLINT NOT NULL,
TRABALHA_FDS BOOLEAN NOT NULL,
TRABALHA_NOITE BOOLEAN NOT NULL,
PRIMARY KEY (CPF)
)ENGINE=InnoDB;
The interesting thing is that, if I create the table separately, only the ones that references each other, for example, I created first PROPRIETARIO and CORRETOR, second INQUILINO, and at last IMOVEL, and this way everything worked. I'm not understanding why I'm getting the error creating them all together in a "single command".
Are you running that exact script? If so, it looks like you're trying to create the foreign keys before you've actually crated the tables they're referencing.
Try changing the order in which you build them.
CREATE TABLE IF NOT EXISTS CORRETOR(
NOME VARCHAR(30) NOT NULL,
CPF INT NOT NULL,
TELEFONE INT NOT NULL,
ANOS_CASA SMALLINT NOT NULL,
TRABALHA_FDS BOOLEAN NOT NULL,
TRABALHA_NOITE BOOLEAN NOT NULL,
PRIMARY KEY (CPF)
)ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS PROPRIETARIO (
NOME VARCHAR(30) NOT NULL,
CPF INT NOT NULL,
TELEFONE INT NOT NULL,
CORRETOR_CPF INT NOT NULL,
PRIMARY KEY (CPF),
FOREIGN KEY (CORRETOR_CPF) REFERENCES CORRETOR(CPF)
)ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS INQUILINO(
NOME VARCHAR(30) NOT NULL,
CPF INT NOT NULL,
TELEFONE INT NOT NULL,
FIADOR BOOLEAN NOT NULL,
INADIMPLENCIA INT NOT NULL,
CORRETOR_CPF INT NOT NULL,
PRIMARY KEY (CPF),
FOREIGN KEY (CORRETOR_CPF) REFERENCES CORRETOR(CPF)
)ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS IMOVEL(
ENDERECO VARCHAR(100) NOT NULL,
TIPO ENUM('ALUGUEL', 'VENDA'),
INQUILINO_CPF INT,
PROPRIETARIO_CPF INT,
VALOR_ALUGUEL_PRECOVENDA INT NOT NULL,
NUM_QUARTOS INT NOT NULL,
METRAGEM INT NOT NULL,
NUM_BANHEIROS INT NOT NULL,
VALOR_CONDOMINIO INT NOT NULL,
IDADE INT NOT NULL,
HORA_REGISTRO TIME NOT NULL,
PRIMARY KEY(ENDERECO),
FOREIGN KEY (INQUILINO_CPF) REFERENCES INQUILINO(CPF),
FOREIGN KEY (PROPRIETARIO_CPF) REFERENCES PROPRIETARIO(CPF)
)ENGINE=InnoDB;

Error on create mysql tables?

Im trying to create a database in mysql, the first bit of my code works fine but then i get a syntax error on:
CREATE TABLE Project_Staff (
empID INT NOT NULL,
projID INT NOT NULL,
CONSTRAINT
i dont understand where is the error.
Here is my code:
CREATE TABLE Employees (
empID INT NOT NULL AUTO_INCREMENT,
empSurname VARCHAR(255) NOT NULL,
empLastname VARCHAR(255) NOT NULL,
empJobtitle VARCHAR(255) NOT NULL,
empLinemanager VARCHAR(255) NOT NULL,
CONSTRAINT pk_employees PRIMARY KEY (empID)
) ENGINE=InnoDB;
CREATE TABLE Skills (
sklID INT NOT NULL AUTO_INCREMENT,
sklName VARCHAR(255) NOT NULL,
CONSTRAINT pk_skills PRIMARY KEY (sklID)
) ENGINE = InnoDB;
CREATE TABLE Employees_Skills (
empskID INT NOT NULL AUTO_INCREMENT,
empskLevel INT NOT NULL,
sklID INT NOT NULL,
empID INT NOT NULL,
CONSTRAINT fk_employees_skills FOREIGN KEY (sklID) REFERENCES Skills(sklID),
CONSTRAINT fk_employees_skills_1 FOREIGN KEY (empID) REFERENCES Employees(empID),
CONSTRAINT pk_employees_skills PRIMARY KEY (empskID)
) ENGINE = InnoDB;
CREATE TABLE Project (
projID INT NOT NULL AUTO_INCREMENT,
projName VARCHAR(255) NOT NULL,
projDuration INT NOT NULL,
projStartdate VARCHAR (255) NOT NULL,
CONSTRAINT pk_project PRIMARY KEY (projID)
) ENGINE = InnoDB
CREATE TABLE Project_Staff (
empID INT NOT NULL,
projID INT NOT NULL,
CONSTRAINT fk_project_staff FOREIGN KEY (empID) REFERENCES Employees(empID),
CONSTRAINT fk_project_staff FOREIGN KEY (projID) REFERENCES Project(projID)
) ENGINE = InnoDB
CREATE TABLE Skill_For_Project (
sklreqDuration INT NOT NULL,
projID INT NOT NULL,
sklID INT NOT NULL,
CONSTRAINT fk_skill_for_project FOREIGN KEY (sklID) REFERENCES Skills(empID),
CONSTRAINT fk_skill_for_project FOREIGN KEY (projID) REFERENCES Project (projID)
) ENGINE = InnoDB
you have Duplicate key name 'fk_project_staff':
Duplicate key name 'fk_skill_for_project':
mising empID in skills table. you may interested in Employees(empID) in Skill_For_Project table.
You have misses Semicolon at the end of Create Table Statement
here full working code
CREATE TABLE Employees (
empID INT NOT NULL AUTO_INCREMENT,
empSurname VARCHAR(255) NOT NULL,
empLastname VARCHAR(255) NOT NULL,
empJobtitle VARCHAR(255) NOT NULL,
empLinemanager VARCHAR(255) NOT NULL,
CONSTRAINT pk_employees PRIMARY KEY (empID)
) ENGINE=InnoDB;
CREATE TABLE Skills (
sklID INT NOT NULL AUTO_INCREMENT,
sklName VARCHAR(255) NOT NULL,
CONSTRAINT pk_skills PRIMARY KEY (sklID)
) ENGINE = InnoDB;
CREATE TABLE Employees_Skills (
empskID INT NOT NULL AUTO_INCREMENT,
empskLevel INT NOT NULL,
sklID INT NOT NULL,
empID INT NOT NULL,
CONSTRAINT fk_employees_skills FOREIGN KEY (sklID) REFERENCES Skills(sklID),
CONSTRAINT fk_employees_skills_1 FOREIGN KEY (empID) REFERENCES Employees(empID),
CONSTRAINT pk_employees_skills PRIMARY KEY (empskID)
) ENGINE = InnoDB;
CREATE TABLE Project (
projID INT NOT NULL AUTO_INCREMENT,
projName VARCHAR(255) NOT NULL,
projDuration INT NOT NULL,
projStartdate VARCHAR (255) NOT NULL,
CONSTRAINT pk_project PRIMARY KEY (projID)
) ENGINE = InnoDB;
CREATE TABLE Project_Staff (
empID INT NOT NULL,
projID INT NOT NULL,
CONSTRAINT fk_project_staff FOREIGN KEY (empID) REFERENCES Employees(empID),
CONSTRAINT fk_project_staff2 FOREIGN KEY (projID) REFERENCES Project(projID)
) ENGINE = InnoDB;
CREATE TABLE Skill_For_Project (
sklreqDuration INT NOT NULL,
projID INT NOT NULL,
sklID INT NOT NULL,
CONSTRAINT fk_skill_for_project FOREIGN KEY (sklID) REFERENCES Employees(empID),
CONSTRAINT fk_skill_for_project2 FOREIGN KEY (projID) REFERENCES Project(projID)
) ENGINE = InnoDB;
http://sqlfiddle.com/#!2/d75182
As far I see, there are two issues
You missed a semicolon after create project table
CREATE TABLE Project
( projID INT NOT NULL AUTO_INCREMENT,
CONSTRAINT pk_project
PRIMARY KEY (projID) ) ENGINE = InnoDB; <-- Here
Both your constraint names (like fk_project_staff in Project_Staff table and fk_skill_for_project in Skill_For_Project table) are same; Try giving them a different name

Cannot Add foreign key constraint Error 1215

I am using Workbench 6.0 and having a frustrating issue I am new to SQl and would like to keep this as simple as possible at this point, I believe my tables are ordered properly to add contraints except for my TICKET table, no idea how to find what foreign key is having problems.
CREATE TABLE IF NOT EXISTS ACTION_TYPE (
ActionCode int primary key,
Description char(50) not null
)ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS OFFICER (
PersonnelNo int primary key,
OfficerLName char(50) not null,
OfficerFName char(50) not null
)ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS DRIVER (
DriverLicenseNo int primary key,
DriverLastName char(50) not null,
DriverFirstName char(50) not null,
DriverAddress char(50) not null,
DriverCity char(50) not null,
DriverProv char(50) not null,
DriverPostalCode varchar(6) not null,
DriverGender char(1) not null,
DriverBirthDate Date not null
)ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS REGISTERED_OWNER (
RegOwnerID int primary key auto_increment,
RegOwnerLName char(50) not null,
RegOwnerFName char(50) not null,
RegOwnerAddress char(50) not null,
RegOwnerCity char(50) not null,
RegOwnerProv char(50) not null,
RegOwnerPostalCode varchar(6) not null
)ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS VEHICLE_TYPE (
VehicleType int primary key,
VehicleDescription char(50) not null
)ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS VEHICLE (
VehicleLicense int primary key,
ProvinceIssued char(2) not null,
VehicleYear int not null,
VehicleMake char(10) not null,
VehicleType int not null,
index (VehicleType),
foreign key (VehicleType)
references VEHICLE_TYPE (VehicleType)
)ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS TICKET ( <-----this table calling the error
TicketNo int primary key auto_increment,
TicketDateTime datetime not null,
TicketLocationCity char(50) not null,
TicketLocationProv char(50) not null,
TicketLocationRoad char(50) not null,
PersonnelNo int not null,
VehicleLicense int not null,
ActionCode int not null,
RegOwnerID int not null,
DriversLicenseNo int not null,
index (PersonnelNo),
foreign key (PersonnelNo)
references OFFICER (PersonnelNo),
index (VehicleLicense),
foreign key (VehicleLicense)
references VEHICLE (VehicleLicense),
index (ActionCode),
foreign key (ActionCode)
references ACTION_TYPE (ActionCode),
index (RegOwnerID),
foreign key (RegOwnerID)
references REGISTERED_OWNER (RegOwnerID),
index (DriversLicenseNo),
foreign key (DriversLicenseNo)
references DRIVER (DriversLicenseNo)
)ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS VIOLATION_TYPE (
ViolationCode int primary key auto_increment,
ViolationDesc char(50) not null,
ViolationCurrFineAmt int not null
)ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS VIOLATION (
ViolationNo int primary key auto_increment,
TicketNo int not null,
ViolationCode int not null,
AppliedFineAmount int not null,
index (TicketNo),
foreign key (TicketNo)
references TICKET (TicketNo),
index (ViolationCode),
foreign key (ViolationCode)
references VIOLATION_TYPE (ViolationCode)
)ENGINE=InnoDB;
Spelling mistake on DriverLicenseNo in TICKET table ane
DriversLicenseNo in DRIVER table