mysql无法与外部健形成约束_mysql - Laravel迁移(错误:150“外键约束形成错误”) - SO中文参考 - www.soinside.com...

我有一个订单表和一个sell_shipping_labels引用orders.id作为外国。但是,当我运行Laravel迁移时,我得到了可怕的错误代码:

[照亮\数据库\ QueryException]

SQLSTATE [HY000]:常规错误:1005无法创建表cheapbooks_test.#sql-b5b_b2a(错误:150“外键约束形成错误”)(SQL:alter table sell_shipping_labels add constraint sell_shipping_labels_order_id_foreign foreign key(order_id)references orders(id))

[学说\ DBAL \驱动\ PDOException]

SQLSTATE [HY000]:常规错误:1005无法创建表cheapbooks_test.#sql-b5b_b2a(错误号:150“外键约束形成错误”)

这是我的orders表架构:

Schema::create('orders', function (Blueprint $table) {

$table->increments('id');

$table->integer('user_id');

$table->integer('book_id');

$table->integer('status_id');

$table->double('payment_amount')->nullable();

$table->timestamp('received_at')->nullable();

$table->timestamp('paid_at')->nullable();

$table->timestamps();

$table->softDeletes();

});

这是我的sell_shipping_labels架构:

Schema::create('sell_shipping_labels', function (Blueprint $table) {

$table->increments('id');

$table->unsignedInteger('order_id');

$table->string('shippo_object_id');

$table->string('label_url');

$table->string('tracking_url');

$table->string('tracking_number');

$table->timestamp('arrived_at');

$table->timestamps();

$table->softDeletes();

$table->foreign('order_id')->references('id')->on('orders');

});

}

现在我已经颠倒了互联网,试图找出问题所在。关于这个问题的所有帖子都提到了这样一个事实,即必须在具有外键的表之前创建订单表,但这对我来说不是问题,因为我的文件的顺序正确。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值