我有三个表(公司,分公司,药品)。我想,“公司表”和“分支表”的主键是在“药品表”一般错误:1215无法添加外键约束laravel 5.3
class CreateMedicinesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('medicines', function (Blueprint $table) {
$table->increments('id');
$table->Integer('company-id')->unsigned();
$table->foreign('company-id')->references('company')->on('id');
$table->Integer('branch-id')->unsigned();
$table->foreign('branch-id')->references('branch')->on('id');
$table->string('name');
$table->string('type');
$table->string('potency');
$table->timestamps();
});
}
外键但错误发生。
Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL
: alter table `medicines` add constraint `medicines_company_id_foreign` for
eign key (`company-id`) references `id` (`company`))
[PDOException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint.
默认情况下是否将表引擎设置为'InnoDB'? –
不,我不知道。如何将表引擎设置为InnoDB? – Haider
将表引擎添加到'InnoDB'作为'MyIsam'不支持关系数据库。 –