这是我的代码
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 行的"无符号不为空,email
varchar(255( 不为空,phone
varchar(255( 不为空"附近使用的正确语法(SQL:创建表employees
(id
bigint unsigned not null auto_increment主键,first_name
varchar(255
second_name
文本不为空,emp_company
varchar(255( 无符号不为空,email
varchar(255( 不为空,phone
varchar(255( 不为空,created_at
时间戳为空,updated_at
时间戳为空( 默认字符集 utf8mb4 整理 'utf8mb4_unicode_ci'(我坚持这个.寻找 SUP 谢谢。
我认为你的问题在这一行:
$table->string('emp_company')->unsigned();
无符号仅用于数字列,以强制仅使用正数, 字符串列没有无符号,这是无意义的
只需删除 ->unsigned(( 您的代码应该可以工作....