MIASTA
CREATE TABLE `miasta` ( `miasto_id` int(11) NOT NULL, `wojewodztwo_id` int(3) NOT NULL, `powiat_id` int(4) NOT NULL, `miasto_nazwa` varchar(255) COLLATE utf8_polish_ci NOT NULL, `miasto_status` int(1) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
POWIATY
CREATE TABLE `powiaty` ( `powiat_id` int(11) NOT NULL, `powiat_nazwa` varchar(255) COLLATE utf8_polish_ci NOT NULL, `powiat_status` int(1) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
WOJEWODZTWA
CREATE TABLE `wojewodztwa` ( `wojewodztwo_id` int(11) NOT NULL, `wojewodztwo_nazwa` varchar(255) COLLATE utf8_polish_ci NOT NULL, `wojewodztwo_status` int(1) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
przy próbie założenia klucza obcego na tabelę POWIATY, kolumna `powiat_id`
ALTER TABLE `powiaty` ADD FOREIGN KEY (`powiat_id`) REFERENCES `miasta`(`powiat_id`);
otrzymuje taki o to błąd:
#1215 - Cannot add foreign key constraint
Co może być nie tak?