I have this symfony application to use as reference and learning tool, and it's not written by me. Anyway to use the application I need to create the database and the tables, but when try to do so with doctrine migrations it complains that there's some syntax errors, since I didn't write the SQL code I have no idea what's wrong because it stops only at users table but other tables are created succesfully.
Here's the error message:
An exception occurred while executing 'CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, email VARCHAR(180) NOT NULL, roles JSON NOT NULL, passw VARCHAR(255) NOT NU
LL, name VARCHAR(50) NOT NULL, is_blocked TINYINT(1) NOT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf
8mb4_unicode_ci ENGINE = InnoDB':
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for th
e right syntax to use near 'JSON NOT NULL, passw VARCHAR(255) NOT NULL, name VARCHAR(50) NOT NULL, is_blocke' at line 1
Here's the generated migration:
$this->addSql('CREATE TABLE country (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(30) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
$this->addSql('CREATE TABLE game (id INT AUTO_INCREMENT NOT NULL, referee_id INT DEFAULT NULL, tournament_id INT NOT NULL, home_team_id INT NOT NULL, away_team_id INT NOT NULL, date DATETIME NOT NULL, round SMALLINT DEFAULT NULL, game_nr SMALLINT NOT NULL, is_playoffs_game TINYINT(1) NOT NULL, playoffs_round SMALLINT DEFAULT NULL, group_nr SMALLINT DEFAULT NULL, home_score SMALLINT DEFAULT NULL, away_score SMALLINT DEFAULT NULL, INDEX IDX_232B318C4A087CA2 (referee_id), INDEX IDX_232B318C33D1A3E7 (tournament_id), INDEX IDX_232B318C9C4C13F6 (home_team_id), INDEX IDX_232B318C45185D02 (away_team_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
$this->addSql('CREATE TABLE player (id INT AUTO_INCREMENT NOT NULL, team_id INT NOT NULL, name VARCHAR(100) NOT NULL, goal_count INT NOT NULL, b_date DATETIME NOT NULL, number SMALLINT DEFAULT NULL, INDEX IDX_98197A65296CD8AE (team_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
$this->addSql('CREATE TABLE team (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, country_id INT NOT NULL, tournament_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, venue VARCHAR(255) DEFAULT NULL, contacts VARCHAR(1000) NOT NULL, region VARCHAR(100) NOT NULL, state SMALLINT NOT NULL, INDEX IDX_C4E0A61FA76ED395 (user_id), INDEX IDX_C4E0A61FF92F3E70 (country_id), INDEX IDX_C4E0A61F33D1A3E7 (tournament_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
$this->addSql('CREATE TABLE tournament (id INT AUTO_INCREMENT NOT NULL, country_id INT NOT NULL, type_id INT NOT NULL, user_id INT NOT NULL, tournament_desc VARCHAR(1000) DEFAULT NULL, rounds SMALLINT DEFAULT NULL, playoffs_places SMALLINT DEFAULT NULL, rounds_per_pair SMALLINT DEFAULT NULL, group_count SMALLINT DEFAULT NULL, players_on_field SMALLINT NOT NULL, rules VARCHAR(1000) DEFAULT NULL, prizes VARCHAR(255) DEFAULT NULL, region VARCHAR(255) NOT NULL, venue VARCHAR(255) DEFAULT NULL, contacts VARCHAR(255) DEFAULT NULL, code VARCHAR(9) NOT NULL, is_started TINYINT(1) NOT NULL, is_ended TINYINT(1) NOT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_BD5FB8D977153098 (code), INDEX IDX_BD5FB8D9F92F3E70 (country_id), INDEX IDX_BD5FB8D9C54C8C93 (type_id), INDEX IDX_BD5FB8D9A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
$this->addSql('CREATE TABLE tournament_type (id INT AUTO_INCREMENT NOT NULL, type VARCHAR(50) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
$this->addSql('CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, email VARCHAR(180) NOT NULL, roles JSON NOT NULL, passw VARCHAR(255) NOT NULL, name VARCHAR(50) NOT NULL, is_blocked TINYINT(1) NOT NULL, UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
$this->addSql('ALTER TABLE game ADD CONSTRAINT FK_232B318C4A087CA2 FOREIGN KEY (referee_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE game ADD CONSTRAINT FK_232B318C33D1A3E7 FOREIGN KEY (tournament_id) REFERENCES tournament (id)');
$this->addSql('ALTER TABLE game ADD CONSTRAINT FK_232B318C9C4C13F6 FOREIGN KEY (home_team_id) REFERENCES team (id)');
$this->addSql('ALTER TABLE game ADD CONSTRAINT FK_232B318C45185D02 FOREIGN KEY (away_team_id) REFERENCES team (id)');
$this->addSql('ALTER TABLE player ADD CONSTRAINT FK_98197A65296CD8AE FOREIGN KEY (team_id) REFERENCES team (id)');
$this->addSql('ALTER TABLE team ADD CONSTRAINT FK_C4E0A61FA76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE team ADD CONSTRAINT FK_C4E0A61FF92F3E70 FOREIGN KEY (country_id) REFERENCES country (id)');
$this->addSql('ALTER TABLE team ADD CONSTRAINT FK_C4E0A61F33D1A3E7 FOREIGN KEY (tournament_id) REFERENCES tournament (id)');
$this->addSql('ALTER TABLE tournament ADD CONSTRAINT FK_BD5FB8D9F92F3E70 FOREIGN KEY (country_id) REFERENCES country (id)');
$this->addSql('ALTER TABLE tournament ADD CONSTRAINT FK_BD5FB8D9C54C8C93 FOREIGN KEY (type_id) REFERENCES tournament_type (id)');
$this->addSql('ALTER TABLE tournament ADD CONSTRAINT FK_BD5FB8D9A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
Related
I have a problem with my Database (using MariaDB) to insert a new row
I Having the following errors
Cannot add or update a child row: a foreign key constraint fails
(DbName_boutique.Commande, CONSTRAINT bdc_managed_by___fk FOREIGN
KEY (bdc_managed_by_user_id) REFERENCES utilisateur
(utilisateur_id))INSERT INTO Commande (lien_devis, lien_bdc,
end_devis, bdc_status, devis_created_by_user_id,
bdc_managed_by_user_id, entreprise_id)
I have this code on my controller :
$unknow = NULL;
$end_date = date('d/m/Y', strtotime("+1 month"));
$user = checkConnected($bdd);
Commande::create($bdd, $new_full_modele_devis_path, $new_full_modele_devis_path, $end_date, 0, $user->getId(), $user->getId(), $entreprise->getId());
The $unknow are values I used later in an another Controller.
My Table "Commande" is built like following :
create table dBName.Commande
(
commande_id int not null
primary key,
lien_devis varchar(255) null,
lien_bdc varchar(255) null,
end_devis datetime null,
bdc_status int null,
devis_created_by_user_id mediumint unsigned null,
bdc_managed_by_user_id mediumint unsigned null,
entreprise_id smallint(5) unsigned null,
constraint bdc_managed_by___fk
foreign key (bdc_managed_by_user_id) references dBName.utilisateur (utilisateur_id),
constraint devis_created_by___fk
foreign key (devis_created_by_user_id) references dBName.utilisateur (utilisateur_id),
constraint entreprise___fk
foreign key (entreprise_id) references dBName.entreprise (entreprise_id)
);
And I have later the user table :
create table dBName.utilisateur
(
utilisateur_id mediumint unsigned auto_increment
primary key,
utilisateur_password varchar(255) null,
utilisateur_nom varchar(50) null,
utilisateur_prenom varchar(50) null,
utilisateur_email varchar(255) null,
utilisateur_telephone varchar(10) null,
utilisateur_fax varchar(25) null,
is_active tinyint(1) null
)
charset = utf8mb4;
And entreprise :
create table dBName.entreprise
(
entreprise_id smallint(5) unsigned auto_increment
primary key,
entreprise_nom varchar(100) null,
entreprise_siret char(14) null,
entreprise_telephone char(10) null,
entreprise_salesforce_number varchar(100) null,
entreprise_compte_client varchar(100) null,
entreprise_raison_sociale varchar(100) null,
entreprise_APE varchar(25) null,
entreprise_image_link varchar(255) null,
adresse_id mediumint unsigned null,
constraint FK_entreprise_adresse_id
foreign key (adresse_id) references dBName.adresse (adresse_id)
)
charset = utf8mb4;
I don't understand Why i'm Habing the error... And bit of help could help me a lot.. Thank you.
In Commande table, the column bdc_managed_by_user_id is mapped to utilisateur_id column of utilisateur table via foreign key reference.
This means, whenever you insert a row in Commande table, corresponding bdc_managed_by_user_id has to be one of the utilisateur_id present in utilisateur table. If not, you will get the above error.
This is called Foreign Key Constraint and you can have a look at this example describing how it works.
This is my t_complaint
CREATE TABLE `t_complaint` (
`idcomplaint` int(11) NOT NULL,
`tglterima` date DEFAULT NULL,
`dept` varchar(5) DEFAULT NULL,
`pengirim` varchar(255) DEFAULT NULL,
`kontak` varchar(255) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`telp` varchar(255) DEFAULT NULL,
`jenis` varchar(45) DEFAULT NULL,
`uraian` text,
`uniqueid` varchar(9) DEFAULT NULL,
`responder` varchar(245) DEFAULT NULL,
`tgljawab` date DEFAULT NULL,
`jawaban` text,
`status` varchar(45) DEFAULT NULL,
`tglclose` date DEFAULT NULL,
`createddate` datetime DEFAULT NULL,
`createdby` varchar(45) DEFAULT NULL,
`modifieddate` datetime DEFAULT NULL,
`modifiedby` varchar(45) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
and this is t_complaint_detail:
CREATE TABLE `t_complaint_detail` (
`no` int(11) NOT NULL,
`uniqueid` varchar(9) DEFAULT NULL,
`uploader` varchar(100) DEFAULT NULL,
`st_uploader` int(11) DEFAULT NULL,
`file_upload` text,
`original_name` text,
`status` int(11) DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
t_complaint.idcomplaint is a primary key with Auto Increment attribute
t_complaint_detail.no is a primary key with Auto Increment attribute
I'd like to connected these table via uniqueid
I've tried ALTER TABLE t_complaint_detail ADD CONSTRAINT fk_unique FOREIGN KEY ('uniqueid') REFERENCES t_complaint('uniqueid')
The query above gives error. The error is #1005 - Can't create tablebsm.#sql-890_730(errno: 150 "Foreign key constraint is incorrectly formed") (Details…)
bsm in the error is my database (my database is bsm)
Foreign key should must be a primary key in parent table. The question is, why you are adding a redundant 'uniqueId' in both the table? You can simply define a foreign key constraint like this :
t_complaint_detail ADD CONSTRAINT fk_unique FOREIGN KEY ('idcomplaint') REFERENCES t_complaint('idcomplaint').
It should work.
Error came like this
ERROR 1215 (HY000): Cannot add foreign key constraint
Because you need to create primary key in table.you can add primary key
like this
alter table t_complaint_detail modify uniqueid varchar(20) not null;
and
alter table t_complaint_detail modify uniqueid varchar(20) not null;
after it will be works
ALTER TABLE t_complaint_detail ADD CONSTRAINT fk_unique FOREIGN KEY (uniqueid) REFERENCES t_complaint(uniqueid);
please read here for more reference that will be help
It's working fine for me :
Try this :
ALTER TABLE t_complaint ADD CONSTRAINT t_complaint_detail
FOREIGN KEY ( uniqueid ) REFERENCES t_complaint( uniqueid )
Reference here :
https://www.w3schools.com/sql/sql_foreignkey.asp
This is my migration:
$table->increments('id');
$table->string('nombre1',255);
$table->string('nombre2',255)->nullable();
$table->string('apellido1',255)->nullable();
$table->string('apellido2',255)->nullable();
$table->string('apellido_casada',255)->nullable();
$table->string('cedula',255)->nullable();
$table->integer('entidad_id')->nulleable()->unsigned();
**$table->integer('cargo_id')->nulleable()->unsigned();
$table->integer('partido_id')->nulleable()->unsigned();
$table->integer('provincia_id')->nulleable()->unsigned();
$table->integer('distrito_id')->nulleable()->unsigned();
$table->integer('corregimiento_id')->nulleable()->unsigned();**
$table->string('otro_nombre',255)->nullable();
$table->dateTime('fecha_nacimiento')->nullable();
$table->timestamps();
$table->softDeletes();
$table->foreign('entidad_id')->references('id')->on('entidad');
$table->foreign('cargo_id')->references('id')->on('cargo');
$table->foreign('partido_id')->references('id')->on('partido');
$table->foreign('provincia_id')->references('id')->on('provincia');
$table->foreign('distrito_id')->references('id')->on('distrito');
$table->foreign('corregimiento_id')->references('id')->on('corregimiento');
When i run this migration the table generated is:
CREATE TABLE pep (
id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
nombre1 VARCHAR(255) COLLATE UTF8_UNICODE_CI NOT NULL,
nombre2 VARCHAR(255) COLLATE UTF8_UNICODE_CI DEFAULT NULL,
apellido1 VARCHAR(255) COLLATE UTF8_UNICODE_CI DEFAULT NULL,
apellido2 VARCHAR(255) COLLATE UTF8_UNICODE_CI DEFAULT NULL,
apellido_casada VARCHAR(255) COLLATE UTF8_UNICODE_CI DEFAULT NULL,
cedula VARCHAR(255) COLLATE UTF8_UNICODE_CI DEFAULT NULL,
**entidad_id INT(10) UNSIGNED NOT NULL,
cargo_id INT(10) UNSIGNED NOT NULL,
partido_id INT(10) UNSIGNED NOT NULL,
provincia_id INT(10) UNSIGNED NOT NULL,
distrito_id INT(10) UNSIGNED NOT NULL,
corregimiento_id INT(10) UNSIGNED NOT NULL,**
otro_nombre VARCHAR(255) COLLATE UTF8_UNICODE_CI DEFAULT NULL,
fecha_nacimiento DATETIME DEFAULT NULL,
created_at TIMESTAMP NULL DEFAULT NULL,
updated_at TIMESTAMP NULL DEFAULT NULL,
deleted_at TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (id),
KEY pep_entidad_id_foreign (entidad_id),
KEY pep_cargo_id_foreign (cargo_id),
KEY pep_partido_id_foreign (partido_id),
KEY pep_provincia_id_foreign (provincia_id),
KEY pep_distrito_id_foreign (distrito_id),
KEY pep_corregimiento_id_foreign (corregimiento_id),
CONSTRAINT pep_cargo_id_foreign FOREIGN KEY (cargo_id)
REFERENCES cargo (id),
CONSTRAINT pep_corregimiento_id_foreign FOREIGN KEY (corregimiento_id)
REFERENCES corregimiento (id),
CONSTRAINT pep_distrito_id_foreign FOREIGN KEY (distrito_id)
REFERENCES distrito (id),
CONSTRAINT pep_entidad_id_foreign FOREIGN KEY (entidad_id)
REFERENCES entidad (id),
CONSTRAINT pep_partido_id_foreign FOREIGN KEY (partido_id)
REFERENCES partido (id),
CONSTRAINT pep_provincia_id_foreign FOREIGN KEY (provincia_id)
REFERENCES provincia (id)
) ENGINE=INNODB DEFAULT CHARSET=UTF8 COLLATE = UTF8_UNICODE_CI;
The problem is that some of the columns: entidad_id, cargo_id, etc, are declared as NULL and when i set the FK, laravel created them as NOT NULL.
Is anyting here that i am missing??
Sorry for being late.
You have typos in code
nulleable
$table->integer('entidad_id')->nulleable()->unsigned();
should be
nullable
$table->integer('entidad_id')->nullable()->unsigned();
Don't know why Laravel is not yelling on typos :(
I am having a problem trying to load my database into MySQL as I am having a few errors with my foreign keys. Things I have tried to do to fix this issue is:
- Putting foreign keys after the primary keys
Eg:
CREATE TABLE IF NOT EXISTS Passenger (
.......
PRIMARY KEY(tNum),
FOREIGN KEY (fNum) REFERENCES Flights(fNum),
FOREIGN KEY (fDate) REFERENCES Flights(fDate),
FOREIGN KEY (sCity) REFERENCES Flights(sCity),
FOREIGN KEY (eCity) REFERENCES Flights(eCity)
);
- Bunching the foreign keys in the format of
Eg:
ALTER TABLE Passenger ADD FOREIGN KEY (fNum, fDate, sCity, eCity) REFERENCES Flights(fNum, fDate, sCity, eCity);
The error I get is:
1005 - Can't create table 'airline.#sql-1d7_7c' (errno: 150)
My full code is:
DROP DATABASE IF EXISTS airline;
CREATE DATABASE IF NOT EXISTS airline;
USE airline;
CREATE TABLE IF NOT EXISTS Flights (
fNum char(6) not null,
pID char(4) not null,
fDate DATE not null,
eDate DATE not null,
sTime char(4) not null,
lTime char(4) not null,
sOStart char(4) null,
sOEnd char(4) null,
sCity varchar(30) not null,
eCity varchar(30) not null,
sOCity varchar(30),
sNum char(5) not null,
PRIMARY KEY (fNum)
);
CREATE TABLE IF NOT EXISTS Passenger (
tNum char(4) not null,
dPurch DATE not null,
pMethod varchar(30) not null,
fNum char(6) not null,
fDate DATE not null,
sCity varchar(30) not null,
eCity varchar(30) not null,
tType varchar(30) not null,
Price decimal(4,2) not null,
iType varchar(30) not null,
idNum char(8) not null,
fName varchar(30) not null,
lName varchar(30) not null,
Sex char(1) not null,
pAddress varchar(30) not null,
pPhone char(8) not null,
pEmail varchar(30) not null,
PRIMARY KEY(tNum)
);
CREATE TABLE IF NOT EXISTS Planes (
pID char(4) not null,
pType char(3) not null,
pDesc varchar(30) not null,
pRange char(4) not null,
Capacity char(3) not null,
mDate DATE not null,
pDate DATE not null,
sDate DATE not null,
PRIMARY KEY (pID)
);
CREATE TABLE IF NOT EXISTS Staff (
sNum char(5) not null,
sName varchar(30) not null,
sDOB DATE not null,
sAddress varchar(30) not null,
pCompany varchar(30) ,
pStart DATE ,
pEnd DATE ,
jID char(1) not null,
PRIMARY KEY (sNum)
);
CREATE TABLE IF NOT EXISTS Emergency (
eID char(5) not null,
sNum char(5) not null,
eName varchar(30) not null,
eAddress varchar(30) not null,
ePhone char(8) not null,
eEmail varchar(30) not null,
eRelationship varchar(30) not null,
PRIMARY KEY(eID)
);
CREATE TABLE IF NOT EXISTS Pilot (
sNum char(5) not null,
pID char(4) not null,
cDate DATE not null,
jID char(1) not null,
PRIMARY KEY(jID)
);
CREATE TABLE IF NOT EXISTS Attendant (
sNum char(5) not null,
tSDate Date not null,
tFDate Date not null,
tDesc Varchar(30) not null,
jID Char(1) not null,
PRIMARY KEY(jID)
);
ALTER TABLE Flights ADD FOREIGN KEY (pID) REFERENCES Planes(pID);
ALTER TABLE Flights ADD FOREIGN KEY (sNum) REFERENCES Staff(sNum);
ALTER TABLE Passenger ADD FOREIGN KEY (fNum) REFERENCES Flights(fNum);
ALTER TABLE Passenger ADD FOREIGN KEY (fDate) REFERENCES Flights(fDate);
ALTER TABLE Passenger ADD FOREIGN KEY (sCity) REFERENCES Flights(sCity);
ALTER TABLE Passenger ADD FOREIGN KEY (eCity) REFERENCES Flights(eCity);
ALTER TABLE Emergency ADD FOREIGN KEY (sNum) REFERENCES Staff(sNum);
ALTER TABLE Pilot ADD FOREIGN KEY (sNum) REFERENCES Staff(sNum);
ALTER TABLE Pilot ADD FOREIGN KEY (pID) REFERENCES Planes(pID);
ALTER TABLE Pilot ADD FOREIGN KEY (jID) REFERENCES Staff(jID);
ALTER TABLE Attendant ADD FOREIGN KEY (sNum) REFERENCES Staff(sNum);
ALTER TABLE Attendant ADD FOREIGN KEY (jID) REFERENCES Staff(jID);
For me this is the one it fails on first
ALTER TABLE Passenger ADD FOREIGN KEY (fDate) REFERENCES Flights(fDate);
Try adding an index on Flights.fdate first, then doing the foreign key and doing that for additional references until it works. Let me know if that works for you, it did for me.
By the way you might want to reconsider your schema there. Joins and relations should really be done on integers only. That schema will bog down fast as it grows. Also, and maybe this is just personal preference but I prefer first_name to fName. Easier to read for other developers, this isn't 1986, we can have human readbable names now :-)
I'm working a project with Yiiframwork and I have this table in my data base project
CREATE TABLE IF NOT EXISTS `tbl_annonce` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`idEntreprise` tinyint(3) unsigned NOT NULL
COMMENT 'CONSTRAINT FOREIGN KEY (idEntreprise) REFERENCES tbl_entreprise(id)',
`titre` varchar(100) NOT NULL,
`detailleDiscription` varchar(5000) NOT NULL,
`categorie` varchar(100) DEFAULT NULL,
`typePoste` varchar(100) NOT NULL,
`salaireMin` varchar(80) NOT NULL,
`salaireMax` varchar(80) NOT NULL,
`niveauEtude` varchar(80) NOT NULL,
`niveauExperience` varchar(80) NOT NULL,
`langue` varchar(50) DEFAULT NULL,
`poste` varchar(50) NOT NULL,
`pays` varchar(50) NOT NULL,
`ville` varchar(50) NOT NULL,
`adresse` varchar(80) NOT NULL,
`datePublication` timestamp NOT NULL
DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`etat` varchar(50) NOT NULL,
`photo` varchar(255) NULL,
`nometr` text NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `fk_idEntrepriseAnn`
FOREIGN KEY (idEntreprise)
REFERENCES tbl_entreprise(id)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
I only use 'comment' because I found it in a tutorial for a yii framework project.
I have got the attribute 'idEntreprise' as FK in my DB but when I entred other 'idEntreprise' that does note exist in my table entreprise it was not problem, instead it must be a problem.
So I added 'identreprise' as Fk and that have this problem now.
Hope you understand my problem :/
can any one helep me plz !!
To define a foreign key on a column, it must fulfil some conditions.
Child and parent column must have same column definition by type,
signed.
Parent column must have an index defined on it.
Make sure that
The column tbl_entreprise.id is indexed.
The column definition idEntreprise tinyint(3) unsigned in tbl_annonce matches
with that of tbl_entreprise.id
Refer to: MySQL: Foregin Key Constaints