Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [SQL][MySQL]Dodane relacji w bazie danych
Malinaa
post
Post #1





Grupa: Zarejestrowani
Postów: 578
Pomógł: 6
Dołączył: 21.07.2008

Ostrzeżenie: (0%)
-----


Mam bazę danych i chciałem dodać relacje:

Kod
ALTER TABLE `post`
  ADD CONSTRAINT `FK_PostSection` FOREIGN KEY (`section_id`) REFERENCES `section` (`id_section`);

ale wyskakuje błąd, kod błędu: 150 Foreign key constraint is incorrectly formed.

Jak dodać relacje do istniejących tabel (w phpMyAdmin)?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Malinaa
post
Post #2





Grupa: Zarejestrowani
Postów: 578
Pomógł: 6
Dołączył: 21.07.2008

Ostrzeżenie: (0%)
-----


Pisze tak (bez ciapek?):

ALTER TABLE post
ADD CONSTRAINT FK_PostSection FOREIGN KEY (section_id) REFERENCES section (id_section);

i też nie idzie?

Indeksy tabel mam tak

ALTER TABLE `post`
ADD PRIMARY KEY (`id_post`),
ADD KEY `section_id` (`section_id`);

ALTER TABLE `section`
ADD PRIMARY KEY (`id_section`);

Chcę utworzyć relacje pomiędzy post a section (post).
Gdzie jest błąd?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 31.12.2025 - 00:21