外键不迁移.我在迁移方面遇到了一些问题.我已经很好地迁移了公司表



这是我的代码

Schema::create('employees', function (Blueprint $table) {
$table->id();
$table->string('first_name');
$table->text('second_name');
$table->string('emp_company')->unsigned();
$table->string('email');
$table->string('phone');
$table->timestamps();
$table->foreign('emp_company')->references('company_name')->on('companies');
});

这是我的错误:

SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误; 检查与您的 MariaDB 服务器版本对应的手册,了解在第 1 行的"无符号不为空,emailvarchar(255( 不为空,phonevarchar(255( 不为空"附近使用的正确语法(SQL:创建表employees(idbigint unsigned not null auto_increment主键,first_namevarchar(255

( 不为空,second_name文本不为空,emp_companyvarchar(255( 无符号不为空,emailvarchar(255( 不为空,phonevarchar(255( 不为空,created_at时间戳为空,updated_at

时间戳为空( 默认字符集 utf8mb4 整理 'utf8mb4_unicode_ci'(我坚持这个.寻找 SUP 谢谢。

我认为你的问题在这一行:

$table->string('emp_company')->unsigned();

无符号仅用于数字列,以强制仅使用正数, 字符串列没有无符号,这是无意义的

只需删除 ->unsigned(( 您的代码应该可以工作....

相关内容

最新更新