PostgreSQL和Perl:违反了外键约束

时间:2016-05-20 08:36:56

标签: postgresql perl

我有表lv和引用的表pozemek,其中包含:

"pozemek_lv_id_fkey" FOREIGN KEY (lv_id) REFERENCES lv(id)

我希望在lv中创建记录,然后在pozemek中创建记录:

my $lv_ins = $kadadbh->prepare("INSERT INTO lv ...");
my $poz_ins= $kadadbh->prepare("INSERT INTO pozemek (lv_id,...) VALUES (?,...)");
$lv_ins->execute(...);
$lv_id = $kadadbh->last_insert_id(undef,undef,'lv','id');
print "lv_id=$lv_id\n";
$poz_ins->execute($lv_id,...);

它返回一个新的lv_id,但因此失败了:

  

lv_id = 8990

     

错误:在表上插入或更新“pozemek”违反了外键约束“pozemek_lv_id_fkey”

     

详细说明:表“lv”中不存在键(lv_id)=(8990)。在./dznxml.pl第121行

0 个答案:

没有答案