Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.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 6中使用外键的表之后列出了引用的表,则无法在迁移中使用外键_Php_Mysql_Laravel_Laravel 6 - Fatal编程技术网

Php 如果在Laravel 6中使用外键的表之后列出了引用的表,则无法在迁移中使用外键

Php 如果在Laravel 6中使用外键的表之后列出了引用的表,则无法在迁移中使用外键,php,mysql,laravel,laravel-6,Php,Mysql,Laravel,Laravel 6,假设我有4个表要迁移,在我的程序中按这些顺序列出 2019_11_11_021524_创建_设备_品牌_table.php 2019_11_11_021820_创建_设备_类型_table.php 2019_11_11_025212_创建_事务_ins_table.php 2019_11_11_150443_创建_设备_状态_table.php 然后我引用了transasctions\u ins public function up() { Schema::create(

假设我有4个表要迁移,在我的程序中按这些顺序列出

2019_11_11_021524_创建_设备_品牌_table.php 2019_11_11_021820_创建_设备_类型_table.php 2019_11_11_025212_创建_事务_ins_table.php 2019_11_11_150443_创建_设备_状态_table.php

然后我引用了
transasctions\u ins

public function up()
    {
        Schema::create('transactions_ins', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('DeviceType_id')->nullable();
            $table->unsignedBigInteger('DeviceBrand_id')->nullable();
            $table->unsignedBigInteger('DeviceStatus_id')->nullable();
            $table->timestamps();

            //Foreign Key
            $table->foreign('DeviceType_id')->references('id')->on('device_types');
            $table->foreign('DeviceBrand_id')->references('id')->on('device_brands');
            $table->foreign('DeviceStatus_id')->references('id')->on('device_statuses');
        });
    }
当我使用
php artisan migrate
迁移表时,会出现此错误

SQLSTATE[HY000]:一般错误:1005无法创建表
清单
事务\u-ins
(错误号:150”外键约束为 格式不正确”)(SQL:alter table
transactions\u-ins
add 约束
transactions\u ins\u devicestatus\u id\u foreign
外键 (
DeviceStatus\u id
)参考
device\u状态
id


但是当我从迁移表中的
transactions\u中删除
DeviceStatus\u id
时,错误消失了,我知道它发生了,因为Laravel不知道
设备状态
表不存在,如何解决这个问题?我应该删除迁移表中的
事务吗?

编辑迁移文件名2019\u 11\u 150443\u创建\u设备\u状态\u table.php。设置在事务\u表之前创建的名称

2019_11_11_023443_create_device_statuses_table.php
这意味着您的表是在事务表之前创建的