外键约束格式不正确。无法添加字符串外键

问题描述 投票:0回答:1

我正在尝试创建字符串外键约束。坚果什么都没有用。帐户表-

Schema::create('accounts', function (Blueprint $table) {
        $table->engine = 'InnoDB';
        $table->string('customer_id');
        $table->foreign('customer_id')->references('customer_id')->on('customers');
        $table->string('ac_type_id');
        $table->string('ac_number')->primary();
        $table->string('ac_balance');
        $table->string('password');
        $table->timestamps();
    });

客户表-

Schema::create('customers', function (Blueprint $table) {
        $table->string('customer_id')->primary();
        $table->string('first_name');
        $table->string('last_name');
        $table->string('mobile_no');
        $table->string('email_id');
        $table->string('address');
        $table->date('dob');[enter image description here][1]
        $table->timestamps();
    });

这是我经常收到的错误This is error I'm getting always

laravel database-migration
1个回答
0
投票

我认为两个表中的引擎应该相同:

 $table->engine = 'InnoDB';

另外请尝试在两个表中为字符串$table->string('customer_id',40)定义一个特定的长度。

© www.soinside.com 2019 - 2024. All rights reserved.