List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:January 9 2003 4:43pm
Subject:Re: Bug in foreign keys
View as plain text  
At 16:11 +0100 1/9/03, Rafal Jank wrote:
>Hi!
>I have two tables:
>CREATE TABLE `pokoje` (
>   `nrpok_p` char(10) NOT NULL default '',
>   `nip_h` int(10) NOT NULL default '0',
>   `lozka_p` char(2) default NULL,
>   `tv_p` char(1) default NULL,
>   `lazienka_p` char(1) default NULL,
>   `cena_p` int(10) default NULL,
>   `zaliczka_p` int(10) default NULL,
>   PRIMARY KEY  (`nrpok_p`,`nip_h`),
>   KEY `nip_h_index` (`nip_h`,`nrpok_p`),
>   FOREIGN KEY (`nip_h`) REFERENCES `hotele` (`nip_h`) ON DELETE CASCADE
>) TYPE=InnoDB;
>
>  CREATE TABLE `rezerwacje` (
>   `id_r` int(10) NOT NULL default '0',
>   `pesel_k` int(11) default NULL,
>   `nip_h` int(10) NOT NULL default '0',
>   `nrpok_p` char(10) NOT NULL default '',
>   `data_r` date default NULL,
>   `od_r` date default NULL,
>   `do_r` date default NULL,
>   `cena_r` int(10) default NULL,
>   `zaliczka_r` int(5) default NULL,
>   `zaplac_r` char(1) default NULL,
>   `wplaczal_r` char(1) default NULL,
>   PRIMARY KEY  (`id_r`),
>   KEY `nip_h_index` (`nip_h`,`nrpok_p`)
>) TYPE=InnoDB;
>
>Now, when I try:
>alter table rezerwacje add foreign key (nip_h,nrpok_p) references
>pokoje(nip_h,nrpok_p);
>I get:
>ERROR 1005: Can't create table './test/#sql-932_4.frm' (errno: 150)
>
>Why?

Circular foreign key relationships?  Removing the FOREIGN KEY
clause from the definition of pokoje allows the ALTER TABLE to work.

>
>
>
>--
>_/        _/  _/_/_/  -----     Rafa½ Jank rjank@stripped     -----
>  _/  _/  _/  _/   _/         Wirtualna Polska SA   http://www.wp.pl
>   _/_/_/_/  _/_/_/    ul. Traugutta 115c, 80-237 Gdansk, tel/fax. (58)5215625
>    _/  _/  _/         --------==*  http://szukaj.wp.pl *==----------
>

Thread
Bug in foreign keysRafal Jank9 Jan
  • Re: Bug in foreign keysPaul DuBois9 Jan
    • Re: Bug in foreign keysRafal Jank9 Jan
  • Re: Bug in foreign keysiConnect \(Berlin\) Stefan Hinz9 Jan
    • Re: Bug in foreign keysRafal Jank10 Jan
Re: Bug in foreign keysHeikki Tuuri9 Jan
Re: Bug in foreign keysHeikki Tuuri9 Jan
  • Re: Bug in foreign keysRafal Jank10 Jan
Re: Bug in foreign keysHeikki Tuuri10 Jan
  • Re: Bug in foreign keysRafal Jank10 Jan