我创建了 2 个 laravel 迁移,第一个运行完美,第二个给我一个错误:
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');
});