22-08-2010, 17:06
|
|
|
חבר מתאריך: 14.08.10
הודעות: 107
|
|
בעייה עם FOREIGN KEY
אהלן,
אני יוצר טבלאות בMySQL ומנסה לעשות FOREIGN KEY ללא הצלחה.
הנה 2 טבלאות שיצרתי:
טבלת היוזרים:
קוד PHP:
CREATE TABLE `Users` ( `RowID` int(11) NOT NULL AUTO_INCREMENT, `Password` text NOT NULL, `UserName` text NOT NULL, `LastIP` text NOT NULL, `AutomaticIPLogin` tinyint(1) DEFAULT '1', `Rules` tinyint(1) DEFAULT '0', `Bans` tinyint(1) DEFAULT '0', `AdminLevel` tinyint(1) DEFAULT '0', `Level` tinyint(1) DEFAULT '0', `Warnings` tinyint(1) DEFAULT '0', `Kills` int(11) DEFAULT '0', `LevelKills` int(11) DEFAULT '0', `Deaths` int(11) DEFAULT '0', `BankMoney` int(11) DEFAULT '0', `LevelsBankMoney` int(11) DEFAULT '0', `MuteTime` int(11) DEFAULT '0', `JailTime` int(11) DEFAULT '0', `PointLocation` text NOT NULL, `PointInterior` tinyint(1) DEFAULT '0', `SpawnLocation` text NOT NULL, `SpawnInterior` tinyint(1) DEFAULT '0', `ClansManagerLevel` tinyint(1) DEFAULT '0', `ClanLevel` tinyint(1) DEFAULT '0', `Time` tinyint(1) DEFAULT '-1', `SkinID` int(11) DEFAULT '-1', `MuteInfo` text NOT NULL, `JailInfo` text NOT NULL, `VIPLevel` tinyint(1) DEFAULT '0', `CreditCard` tinyint(1) DEFAULT '0', `LastLoginTime` int(11) DEFAULT '0', `ClanID` tinyint(1) DEFAULT '0', PRIMARY KEY (`RowID`) )
וטבלה שאמורה להיות קשורה ליוזרים:
קוד PHP:
CREATE TABLE `UsersMessageOptions` ( `UserID` int(11) NOT NULL, `ServerConnect` tinyint(1) DEFAULT '1', `GameConnect` tinyint(1) DEFAULT '0', `AccountRegister` tinyint(1) DEFAULT '0', `AccountLogin` tinyint(1) DEFAULT '0', `AutomaticAccountLogin` tinyint(1) DEFAULT '0', `FailAccountLogin` tinyint(1) DEFAULT '0', `GameLogin` tinyint(1) DEFAULT '1', `AFK` tinyint(1) DEFAULT '1', `AutomaticAFK` tinyint(1) DEFAULT '1', `ServerDisconnect` tinyint(1) DEFAULT '1', FOREIGN KEY (`UserID`) REFERENCES Users(`RowID`) )
כמו שאתם רואים בטבלה השנייה יצרתי FOREIGN KEY לטבלה Users לעמודה RowID.
הבעייה שאני יכול להוסיף לטבלה UsersMessageOptions בעמודה UserID גם ID שלא קיימים בעמודה RowID בטבלה Users.
איך אני מסדר את הבעייה (ולמה היא נגרמת)?
תודה
|