Laravel 外键约束的格式不正确。无法添加字符串外键
我正在尝试创建字符串外键约束。什么也没用。 账目表-Laravel 外键约束的格式不正确。无法添加字符串外键,laravel,database-migration,Laravel,Database Migration,我正在尝试创建字符串外键约束。什么也没用。 账目表- Schema::create('accounts', function (Blueprint $table) { $table->engine = 'InnoDB'; $table->string('customer_id'); $table->foreign('customer_id')->references('customer_id')->on('custom
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();
});
这是我经常犯的错误
客户表是在Accounts表之前创建的吗?如果没有,则Accounts表无法引用客户id。这是我通常遇到的问题。是的,Customer表是在accounts table@Geertjankanapen之前创建的。您是否尝试为两个表中的字符串
$table->string('Customer_id',40)
定义特定长度