我创建了2个Laravel迁移,第一个运行得很完美,第二个却出现了错误:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
我不确定我的外键有什么问题,有人可以帮我吗?
这是我的第一个模式:
这是我的第二个模式:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
我不确定我的外键有什么问题,有人可以帮我吗?
这是我的第一个模式:
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');
});