J'ai une table "théâtres". Dans lequel (theater_name, area_name, station) sont des clés composites. Et dans la table "cubelists" j'ai des colonnes (thtr_name, area, stn) auxquelles il faut se référer (theater_name, area_name, station) de la table "theaters".La contrainte de clé étrangère est incorrectement formée avec des touches composites
Le problème ici est la combinaison des colonnes - (nom_théâtre, nom_zone, station) dans la table "théâtres" est unique car il s'agit d'une clé composite. Mais chaque colonne séparément n'est pas unique.
Alors comment puis-je référencer ces colonnes de la table "cubelists"?
Schema::create('theaters', function (Blueprint $table) {
$table->string('theater_name');
$table->string('area_name');
$table->string('station');
$table->primary(array('theater_name','area_name','station'));
$table->text('address');
$table->bigInteger('phno');
$table->string('contact_person');
});
public function up()
{
//
Schema::create('cubelists', function (Blueprint $table) {
$table->string('mvie_name');
$table->foreign('mvie_name')->references('movie_name')->on('movies');
$table->string('thtr_name');
$table->string('area');
$table->string('stn');
$table->foreign(array('thtr_name','area','stn'))-
>references(array('theater_name','area_name','station'))-
>on('theaters');
$table->primary(array('mvie_name','thtr_name','area','stn'));
$table->string('type');
$table->string('subtype');
$table->date('validity');
$table->string('show');
});
}
Si je donne le code ci-dessus je reçois une erreur
Migration table created successfully.
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1005 Can't create table `boras_cachii`.`#sql-a10_
112` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter tabl
e `agreements` add constraint agreements_area_name_foreign foreign key (`area_nam
e`) references `cubelists` (`area`))
[PDOException]
SQLSTATE[HY000]: General error: 1005 Can't create table `boras_cachii`.`#sql-a10_
112` (errno: 150 "Foreign key constraint is incorrectly formed")
boras_cachii est le nom de la base de données – Muthu