我创建了两个laavel迁移,第一个运行得很好,第二个给我一个错误:

SQLSTATE[23000]:完整性约束冲突:1452无法添加或 更新子行:外键约束失败

我不知道我的外卡出了什么问题,有人能帮帮我吗?

以下是我的第一个架构:

    Schema::create('cryptocurrencies', function (Blueprint $table) {
        $table->id('id');
        $table->string('name');
        $table->string('symbol')->unique();
        $table->string('slug');
        $table->longtext('description');
    });

以下是我的第二个架构:

Schema::create('cryptocurrencies_quotes', function (Blueprint $table) {
    $table->id('id');
    $table->string('name');
    $table->string('symbol');
    $table->string('slug');
    $table->integer('cryptocurrency_id');
    $table->bigInteger('circulating_supply');
    $table->bigInteger('total_supply');
    $table->double('price');
    $table->double('volume_24h');
    $table->timestamps();
});

Schema::table('cryptocurrencies_quotes', function (Blueprint $table) {
    $table->foreign('cryptocurrency_id')->references('id')->on('cryptocurrencies')->onUpdate('cascade')->onDelete('cascade');
});

推荐答案

这意味着我们传递给Table2的值不是作为父级存在于Table1中的 在您的第二个表中更改

$table->integer('cryptocurrency_id');

$table->unsignedBigInteger('cryptocurrency_id');

Php相关问答推荐

为什么注册SIGHUP的处理程序函数会阻止在PHP CLI中等待输入时点击X关闭Xterm窗口?""

Htaccess-重写对&api.php";的API请求以及对";web.php";的其他请求

在特定订单状态更改时自定义WooCommerce订单发货项目

在内部API请求之后,在响应客户端之前,是否忘记了PHP中的Header()?

如何保存基于用户 Select 的复选框 Select 模式

用GUZLE模拟Read_Timeout

未检测到laravel控制器

以编程方式同步 WPML 翻译更改 Woocommerce 产品销售价格

在 WooCommerce 订阅续订订单中设置送货方式

PHP API - 本地主机中的 SSL 证书问题

Symfony:指定 data_class 时,提交的表单获取初始化前不得访问

如何获得没有运输等级的产品

WooCommerce订单支付页面上的附加支付订单按钮

优化后的标题:如何在WooCommerce我的帐户编辑表单中添加账单字段

Shopware 6.4.20店铺激活问题

PHP preg_replace括号和方括号内的所有逗号

docker |管道失败的 ubuntu 源列表

为什么在解压缩具有混合字符串和 int 键的关联数组时出现错误消息无法使用位置参数...?

使用来自 PHP 表单的数据更新 xml 命名空间

PHP 自动函数参数和变量