【发布时间】:2022-01-29 09:39:14
【问题描述】:
在创建用户表模式和 user_type 表模式后,它经常给我外键问题我将 db 设置为 utf8 如果它可能是一个问题,我已经打了几个小时但我不能摆脱它。
Schema::create('users_panel', function (Blueprint $table) {
$table
->id();
$table
->unsignedBigInteger('id_type_user');
$table
->string('company_name');
$table
->string('email')->unique();
$table
->string('password', 60);
$table
->timestamp('email_verified_at')
->nullable();
$table
->string('representative_name')
->nullable();
$table
->string('phone_number')
->nullable();
$table
->string('address');
$table
->rememberToken();
$table
->timestamps();
});
Schema::table('users_panel', function (Blueprint $table) {
$table
->foreign('id_type_user')
->references('id')
->on('type_users')
->onDelete('cascade');
});
type_users:
Schema::create('type_users', function (Blueprint $table) {
$table->id();
$table->string('type_user');
$table->timestamps();
});
错误:
PDOException::("SQLSTATE[HY000]: 一般错误: 1005 无法创建表prysma_db.users_panel (errno: 150 "外键约束格式不正确")")
【问题讨论】: