Answer the question
In order to leave comments, you need to log in
Foreign key constraint is incorrectly formed / I can't create a VC, what's the problem?
I get an error while migrating
Foreign key constraint is incorrectly formedI'm not strong in the database, tell me what I'm doing wrong.
public function safeUp()
{
$this->createTable('profile', [
'id' => $this->primaryKey(),
'surname' => $this->string()->notNull(),
'name' => $this->string()->notNull(),
'email' => $this->string()->notNull(),
'gender' => $this->string()->defaultValue("MAN"),
'birthday' => $this->date(),
'telephone' => $this->string(),
'site' => $this->string(),
'role' => $this->string()->notNull(),
'company' => $this->string(),
'about' => $this->text(),
'city' => $this->string(),
]);
$this->addForeignKey(
'fk-profile-id-user',
'profile',
'id',
'user',
'id',
'NO ACTION',
'CASCADE'
);
$this->addForeignKey(
'fk-profile-email-user',
'profile',
'email',
'user',
'email',
'NO ACTION',
'CASCADE'
);
}
Answer the question
In order to leave comments, you need to log in
Has a unique index been created for the user.email field? The primary key can only point to a field that does not allow duplicate values.
But the situation itself, when two duplicate links are implemented between two tables for different pairs of fields, looks at least strange.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question