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 (1 - 4)
Pyton_000
post
Post #2





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


wywal ciapki
Go to the top of the page
+Quote Post
Malinaa
post
Post #3





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
trueblue
post
Post #4





Grupa: Zarejestrowani
Postów: 6 809
Pomógł: 1828
Dołączył: 11.03.2014

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


Błąd może być w:
- różnym typie pól,
- taki sam typ pola, ale jedno UNSIGNED, drugie nie,
- taki sam typ pola i znak, ale jedno NOT NULL, a drugi nie.

Go to the top of the page
+Quote Post
Malinaa
post
Post #5





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

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


Dzięki trueblue. Atrybuty były różne, dodałem UNSIGNED dla wszystkich ID i poszło (ciapki są ok ; )
Go to the top of the page
+Quote Post

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: 23.12.2025 - 19:32