DragonPrime - LoGD Resource Community
Welcome Guest
  • Good afternoon, Guest.
    Please log in, or register.
  • November 27, 2014, 12:27:37 PM
Home Forums News Links Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Login
 
 
Resource Pages
IRC Channels
Search

Pages: [1]   Go Down
  Print  
Author Topic: MySQL Foreign Key Help  (Read 829 times)
0 Members and 1 Guest are viewing this topic.
KaosKaizer
Mod God
*****
Offline Offline

Posts: 1016


Zeno's Arrow never hits the mark.


View Profile
« on: June 08, 2011, 06:14:55 PM »

I'm working on my Religion Overhaul, and I need to create a table with the MySQL "FOREIGN KEY" as part of it. I think I got it right, but this is the first time I have ever used it, so I don't know. I would test it, but the module is far from being done and thus have no way to test it. Anyways, here's the SQL Create Table statement with the FOREIGN KEY.

Code:
$sql = "CREATE TABLE `".db_prefix("religion_ranks")."` (
   `id` int(11) NOT NULL auto_increment,
   `did` int(11) NOT NULL default 0,
   `faith` int(11) NOT NULL default 0,
   `rank` varchar(255) NOT NULL default '',
   PRIMARY KEY (id)
   FOREIGN KEY (did) REFERENCES ".db_prefix("deities")."(did)
   ) TYPE=MyISAM COMMENT='This holds the follower ranks info for the Religion module.' AUTO_INCREMENT=1 ;";
Logged

My Mods
I'm not currently a fully active member of DP, though I do respond to most PMs.
vokainer
Captain of the Guard
***
Offline Offline

Posts: 174


View Profile
« Reply #1 on: June 09, 2011, 05:59:55 AM »

MyIsam does not support Foreignkeys.
That is the bad thing with MyIsam. If you use InnoDB instead of that you are able to use foreign keys, but innoDB has no support for fulltext indizes.
Logged
KaosKaizer
Mod God
*****
Offline Offline

Posts: 1016


Zeno's Arrow never hits the mark.


View Profile
« Reply #2 on: June 09, 2011, 08:35:15 AM »

Dang it. I guess that I can't use my Foreign Key then. Thanks for the help.
Logged

My Mods
I'm not currently a fully active member of DP, though I do respond to most PMs.
Afkamm
Mod God
*****
Offline Offline

Posts: 1677

MarcTheSlayer


View Profile WWW
« Reply #3 on: June 09, 2011, 09:28:10 AM »

How come you're not using the built in functions to create the SQL table?
Logged

KaosKaizer
Mod God
*****
Offline Offline

Posts: 1016


Zeno's Arrow never hits the mark.


View Profile
« Reply #4 on: June 09, 2011, 10:04:50 AM »

Because I don't know them Huh . And all my modules that create tables do it like this. It's the way I learned how to create them.
Logged

My Mods
I'm not currently a fully active member of DP, though I do respond to most PMs.
Boris735
Mod God
*****
Offline Offline

Posts: 553


View Profile
« Reply #5 on: June 09, 2011, 04:51:21 PM »

There is some small benefit to using synctable() instead of directly calling the SQL yourself.  If you adjust the table fields in some fashion then synctable() will make the right thing happen, whether the table already exists or not.  So it simplifies upgrades for your install routine to use that instead.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  


*
DragonPrime Notices
Please take the time to read the FAQ and browse the DragonPedia

Support Us
No funds raised yet this year
Your help is greatly appreciated!
Who's Online
50 Guests, 0 Users
DragonPrime LoGD
Recent Topics
Home Forums News Links Downloads Login Register Advanced Search