我有三個表(公司,分公司,藥品)。我想,「公司表」和「分支表」的主鍵是在「藥品表」一般錯誤: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'不支持關係數據庫。 –