您好,我仍然收到此错误,但是一切看起来不错,并且迁移工作正常。
SQLSTATE [23000]:违反完整性约束:1452无法添加或更新子行:外键约束失败([
fakturytable
。fakturas
,约束fakturas_id_sprzedawcy_foreign
外键(id_sprzedawcy
)在删除级联中的引用sprzedawcas
(id
)(SQL:插入fakturas
(typ_faktury
,data_wystawienia
,mejsce_wystawienia
,data_sprzedazy
,towar_usluga
,jm
,ilosc
,cena_netto
,watosc_netto
,stawka_vat
,kwota_vat
,wartosc_brutto
,status
,sposob_platnosci
,numer_konta
,termin_platnosci
)值(fsturaVAT,2020.10.14,明斯克Mazowiecki,2020.10.26,Porty,1月10日,23456,421124,1234,207,1107,nieaplacona,qwrq,12345678901234567890098321,2020.10.28)))>fakturas迁移:
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateFakturasTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('fakturas', function(Blueprint $table){
$table->increments('id');
$table->unsignedinteger('id_sprzedawcy');
$table->unsignedinteger('id_nabywcy');
$table->string('typ_faktury');
$table->date('data_wystawienia');
$table->string('mejsce_wystawienia');
$table->date('data_sprzedazy');
$table->string('towar_usluga');
$table->string('jm');
$table->bigInteger('ilosc');
$table->bigInteger('cena_netto');
$table->bigInteger('watosc_netto');
$table->bigInteger('stawka_vat');
$table->bigInteger('kwota_vat');
$table->bigInteger('wartosc_brutto');
$table->string('status');
$table->string('sposob_platnosci');
$table->string('numer_konta');
$table->date('termin_platnosci');
});
Schema::table('fakturas',function($table){
$table->foreign('id_sprzedawcy')
->references('id')->on('sprzedawcas')
->onDelete('cascade');
$table->foreign('id_nabywcy')
->references('id')->on('nabywcas')
->onDelete('cascade');
});
}
public function down()
{
Schema::dropIfExists('fakturas');
Schema::enableForeignKeyConstraints();
}
}
您好,我仍然收到此错误,但是一切看起来不错,并且迁移工作正常。 SQLSTATE [23000]:违反完整性约束:1452无法添加或更新子行:外键...
您的插入不正确。
在插入时,您没有提供id_sprzedawcy的值(该值应该是sprzedawcas表中存在的ID)。要么在create语句中提供它,要么在迁移中使其为空:
$table->unsignedinteger('id_sprzedawcy')->nullable();