为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
温温酱 2023-07-01 10:09:08
这是我的代码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 行“unsigned not null, emailvarchar(255) not null, varchar(255) not null,”附近使用的正确语法(SQL: create table ( bigint unsigned not null auto_increment 主键、varchar(255) not null、text not null、varchar(255) unsigned not null、varchar(255) not null、varchar(255) not null、timestamp null、timestamp null) 默认字符集 utf8mb4 collate 'utf8mb4_unicode_ci ')phoneemployeesidfirst_namesecond_nameemp_companyemailphonecreated_atupdated_at我坚持这个..寻找支持谢谢。
查看完整描述

1 回答

?
三国纷争

TA贡献1804条经验 获得超7个赞

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

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

unsigned 仅用于数字列,强制只使用正数,字符串列没有 UNSIGNED,没有意义

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


查看完整回答
反对 回复 2023-07-01
  • 1 回答
  • 0 关注
  • 85 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信