Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 5.1-一般错误:1005 Can';t创建表(mysql)_Php_Mysql_Laravel_Laravel 5.1 - Fatal编程技术网

Php Laravel 5.1-一般错误:1005 Can';t创建表(mysql)

Php Laravel 5.1-一般错误:1005 Can';t创建表(mysql),php,mysql,laravel,laravel-5.1,Php,Mysql,Laravel,Laravel 5.1,我正在使用laravel迁移一些数据,但我有以下消息: [Illuminate\Database\QueryException] SQLSTATE[HY000]: Genera

我正在使用laravel迁移一些数据,但我有以下消息:

[Illuminate\Database\QueryException]                                                                                                                                                                
  SQLSTATE[HY000]: General error: 1005 Can't create table 'heinz.#sql-1e83_8' (errno: 150) (SQL: alter table `funcionarios` add constraint funcionarios_supervisor_id_foreign foreign key (`supervis  
  or_id`) references `funcionarios` (`id`))  
我做了很多尝试,但都没有成功

这是迁移文件的代码。(有关部分)


在没有看到表结构的情况下,从下面的查询可以看出

id
supervisor\u id
与数据类型和大小不匹配。确保此列的数据类型和大小相同

另外,检查是否已经存在名为
functionarios\u supervisor\u id\u foreign
的任何其他约束。如果是,请尝试为约束提供其他名称

alter table `funcionarios` add constraint funcionarios_supervisor_id_foreign 
foreign key (`supervisor_id`) references `funcionarios` (`id`)  

在没有看到表结构的情况下,从下面的查询可以看出

id
supervisor\u id
与数据类型和大小不匹配。确保此列的数据类型和大小相同

另外,检查是否已经存在名为
functionarios\u supervisor\u id\u foreign
的任何其他约束。如果是,请尝试为约束提供其他名称

alter table `funcionarios` add constraint funcionarios_supervisor_id_foreign 
foreign key (`supervisor_id`) references `funcionarios` (`id`)  

当代码中存在错误的主键引用时,您会得到错误代码1005。以下是调试代码的方法:

  • 确保您引用的FK确实存在
  • 确保你没有打字错误。情况也必须相同
  • FK链接字段必须与定义完全匹配

  • 当代码中存在错误的主键引用时,您会得到错误代码1005。以下是调试代码的方法:

  • 确保您引用的FK确实存在
  • 确保你没有打字错误。情况也必须相同
  • FK链接字段必须与定义完全匹配

  • 所有外键都必须是未签名的

        $table->integer('supervisor_id')->unsigned()->nullable();
        $table->integer('coordenador_id')->unsigned()->nullable();
        $table->integer('gerente_id')->unsigned()->nullable();
        $table->integer('diretor_id')->unsigned()->nullable();
        $table->integer('sexo_id')->unsigned()->nullable();
        $table->integer('setor_id')->unsigned()->nullable();
        $table->integer('cargo_id')->unsigned();
        $table->integer('turno_id')->unsigned()->nullable();
    

    (来源:)

    您的所有外键都必须是未签名的

        $table->integer('supervisor_id')->unsigned()->nullable();
        $table->integer('coordenador_id')->unsigned()->nullable();
        $table->integer('gerente_id')->unsigned()->nullable();
        $table->integer('diretor_id')->unsigned()->nullable();
        $table->integer('sexo_id')->unsigned()->nullable();
        $table->integer('setor_id')->unsigned()->nullable();
        $table->integer('cargo_id')->unsigned();
        $table->integer('turno_id')->unsigned()->nullable();
    

    (来源:)

    首先需要检查迁移文件的执行顺序。引用的表迁移应在完整性约束中引用之前完成。

    需要首先检查迁移文件的执行顺序。引用的表迁移应在完整性约束中引用它之前完成。

    supervisor\u id引用了相同的表“Functionarios”,并且两者都是相同的类型。并且不存在具有相同名称的另一个约束。“supervisor_id”引用了相同的表“Functionarios”,并且两者的类型相同。并且不存在另一个同名约束。Fk引用同一个表“Functionarios”,因此它实际上存在。显然,一切都是匹配的。但错误不断出现。Fk引用了同一个表“Functionarios”,因此它实际上存在。显然,一切都是匹配的。但是错误不断出现。不要等待。我只是忘了一把钥匙,让它不签字。成功了!Amarnasan,你怎么知道外部表中的键没有签名?不,等等。我只是忘了一把钥匙,让它不签字。成功了!Amarnasan,你怎么知道外部表中的键没有签名?