I tired checking the relationship of the two tables, and matched everything up to see if they were using different engines. But for some reason I cannot create the "buddies" table:
DROP TABLE IF EXISTS `buddies`;
CREATE TABLE `buddies` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`characterid` int(11) NOT NULL,
`buddyid` int(11) NOT NULL,
`pending` tinyint(4) NOT NULL DEFAULT '0',
`groupname` varchar(16) NOT NULL DEFAULT 'ETC',
PRIMARY KEY (`id`),
KEY `buddies_ibfk_1` (`characterid`),
CONSTRAINT `buddies_ibfk_1` FOREIGN KEY (`characterid`) REFERENCES `characters` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=7998 DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
DROP TABLE IF EXISTS `characters`;
CREATE TABLE `characters` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`accountid` int(11) NOT NULL DEFAULT '0',
`world` tinyint(1) NOT NULL DEFAULT '0',
`name` varchar(13) NOT NULL DEFAULT '',
`level` int(3) NOT NULL DEFAULT '0',
`exp` int(11) NOT NULL DEFAULT '0',
`str` int(5) NOT NULL DEFAULT '0',
`dex` int(5) NOT NULL DEFAULT '0',
`luk` int(5) NOT NULL DEFAULT '0',
`int` int(5) NOT NULL DEFAULT '0',
`hp` int(5) NOT NULL DEFAULT '0',
`mp` int(5) NOT NULL DEFAULT '0',
`maxhp` int(5) NOT NULL DEFAULT '0',
`maxmp` int(5) NOT NULL DEFAULT '0',
`meso` int(11) NOT NULL DEFAULT '0',
`hpApUsed` int(5) NOT NULL DEFAULT '0',
`job` int(5) NOT NULL DEFAULT '0',
`skincolor` tinyint(1) NOT NULL DEFAULT '0',
`gender` tinyint(1) NOT NULL DEFAULT '0',
`fame` int(5) NOT NULL DEFAULT '0',
`hair` int(11) NOT NULL DEFAULT '0',
`face` int(11) unsigned NOT NULL DEFAULT '0',
`faceMarking` int(11) NOT NULL DEFAULT '0',
`ap` int(11) NOT NULL DEFAULT '0',
`map` int(11) NOT NULL DEFAULT '0',
`spawnpoint` int(3) NOT NULL DEFAULT '0',
`gm` int(3) NOT NULL DEFAULT '0',
`party` int(11) NOT NULL DEFAULT '0',
`buddyCapacity` int(11) NOT NULL DEFAULT '25',
`createdate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`guildid` int(10) unsigned NOT NULL DEFAULT '0',
`guildrank` tinyint(1) unsigned NOT NULL DEFAULT '5',
`allianceRank` tinyint(1) unsigned NOT NULL DEFAULT '5',
`guildContribution` int(11) NOT NULL DEFAULT '0',
`pets` varchar(13) NOT NULL DEFAULT '-1,-1,-1',
`sp` varchar(255) NOT NULL DEFAULT '0,0,0,0,0,0,0,0,0,0',
`subcategory` int(11) NOT NULL DEFAULT '0',
`rank` int(11) NOT NULL DEFAULT '1',
`rankMove` int(11) NOT NULL DEFAULT '0',
`jobRank` int(11) NOT NULL DEFAULT '1',
`jobRankMove` int(11) NOT NULL DEFAULT '0',
`marriageId` int(11) NOT NULL DEFAULT '0',
`familyid` int(11) NOT NULL DEFAULT '0',
`seniorid` int(11) NOT NULL DEFAULT '0',
`junior1` int(11) NOT NULL DEFAULT '0',
`junior2` int(11) NOT NULL DEFAULT '0',
`currentrep` int(11) NOT NULL DEFAULT '0',
`totalrep` int(11) NOT NULL DEFAULT '0',
`gachexp` int(11) NOT NULL DEFAULT '0',
`fatigue` tinyint(4) NOT NULL DEFAULT '0',
`charm` mediumint(7) NOT NULL DEFAULT '0',
`craft` mediumint(7) NOT NULL DEFAULT '0',
`charisma` mediumint(7) NOT NULL DEFAULT '0',
`will` mediumint(7) NOT NULL DEFAULT '0',
`sense` mediumint(7) NOT NULL DEFAULT '0',
`insight` mediumint(7) NOT NULL DEFAULT '0',
`totalWins` int(11) NOT NULL DEFAULT '0',
`totalLosses` int(11) NOT NULL DEFAULT '0',
`pvpExp` int(11) NOT NULL DEFAULT '0',
`pvpPoints` int(11) NOT NULL DEFAULT '0',
`rebirths` int(11) NOT NULL DEFAULT '0',
`prefix` varchar(45) DEFAULT NULL,
`reborns` int(11) NOT NULL DEFAULT '0',
`apstorage` int(11) NOT NULL DEFAULT '0',
`elf` int(11) NOT NULL DEFAULT '0',
`honourExp` int(11) NOT NULL DEFAULT '0',
`honourLevel` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `accountid` (`accountid`),
KEY `guildid` (`guildid`),
KEY `familyid` (`familyid`),
KEY `marriageId` (`marriageId`),
KEY `seniorid` (`seniorid`)
) ENGINE=InnoDB AUTO_INCREMENT=124 DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
Well every time I execute above, I get:Error Code: 1005. Can't create table (errno: 150) 0.000 sec
Put the buddies last so it can reference characters.
http://sqlfiddle.com/#!2/b359c
Have you tried changing the order of the create tables? Buddies is trying to create a table with a foreign key constraint off of characters which may not exist yet.
Related
After migrating from myiasm to innodb the following query fails unexpectedly
SELECT postid, post.dateline
FROM post AS post USE INDEX (threadid)
INNER JOIN thread AS thread ON(thread.threadid = post.threadid)
WHERE MATCH(post.title, post.pagetext) AGAINST ('+match1 +match2' IN BOOLEAN MODE) AND thread.threadid = <my_id>;
If I remove USE INDEX (threadid) the query works
If I instead remove MATCH(post.title, post.pagetext) AGAINST ('+match1 +match2' IN BOOLEAN MODE) AND the query also works.
I am using version 5.6.19-log
Relevant portions of schema:
CREATE TABLE `post` (
`postid` int(10) unsigned NOT NULL AUTO_INCREMENT,
`threadid` int(10) unsigned NOT NULL DEFAULT '0',
`username` varchar(100) NOT NULL DEFAULT '',
`userid` int(10) unsigned NOT NULL DEFAULT '0',
`title` varchar(250) NOT NULL DEFAULT '',
`dateline` int(10) unsigned NOT NULL DEFAULT '0',
`pagetext` mediumtext NOT NULL,
`allowsmilie` smallint(6) NOT NULL DEFAULT '0',
`showsignature` smallint(6) NOT NULL DEFAULT '0',
`ipaddress` varchar(16) NOT NULL DEFAULT '',
`iconid` smallint(5) unsigned NOT NULL DEFAULT '0',
`visible` smallint(6) NOT NULL DEFAULT '0',
`parentid` int(10) unsigned NOT NULL DEFAULT '0',
`attach` smallint(5) unsigned NOT NULL DEFAULT '0',
`infraction` smallint(5) unsigned NOT NULL DEFAULT '0',
`reportthreadid` int(10) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`postid`),
KEY `userid` (`userid`),
KEY `threadid` (`threadid`,`userid`),
FULLTEXT KEY `title` (`title`,`pagetext`)
)
CREATE TABLE `thread` (
`threadid` int(10) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(250) NOT NULL DEFAULT '',
`lastpost` int(10) unsigned NOT NULL DEFAULT '0',
`forumid` smallint(5) unsigned NOT NULL DEFAULT '0',
`pollid` int(10) unsigned NOT NULL DEFAULT '0',
`open` tinyint(4) NOT NULL DEFAULT '0',
`replycount` int(10) unsigned NOT NULL DEFAULT '0',
`postusername` varchar(100) NOT NULL DEFAULT '',
`postuserid` int(10) unsigned NOT NULL DEFAULT '0',
`lastposter` varchar(100) NOT NULL DEFAULT '',
`dateline` int(10) unsigned NOT NULL DEFAULT '0',
`views` int(10) unsigned NOT NULL DEFAULT '0',
`iconid` smallint(5) unsigned NOT NULL DEFAULT '0',
`notes` varchar(250) NOT NULL DEFAULT '',
`visible` smallint(6) NOT NULL DEFAULT '0',
`sticky` smallint(6) NOT NULL DEFAULT '0',
`votenum` smallint(5) unsigned NOT NULL DEFAULT '0',
`votetotal` smallint(5) unsigned NOT NULL DEFAULT '0',
`attach` smallint(5) unsigned NOT NULL DEFAULT '0',
`firstpostid` int(10) unsigned NOT NULL DEFAULT '0',
`similar` varchar(55) NOT NULL DEFAULT '',
`hiddencount` int(10) unsigned NOT NULL DEFAULT '0',
`deletedcount` smallint(5) unsigned NOT NULL DEFAULT '0',
`lastpostid` int(10) unsigned NOT NULL DEFAULT '0',
`prefixid` varchar(25) NOT NULL DEFAULT '',
`taglist` mediumtext,
PRIMARY KEY (`threadid`),
KEY `forumid` (`forumid`,`visible`,`sticky`,`lastpost`),
KEY `postuserid` (`postuserid`),
KEY `postuserid_2` (`postuserid`),
KEY `pollid` (`pollid`),
KEY `lastpost` (`lastpost`,`forumid`),
KEY `dateline` (`dateline`),
KEY `prefixid` (`prefixid`,`forumid`),
FULLTEXT KEY `title` (`title`)
)
Could this be a bug in innodb?
Dropping USE INDEX (threadid) would not matter I guess, the query planner is smart enough
I have a table:
CREATE TABLE `posts` (
`post_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`topic_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
`forum_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
`poster_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
`icon_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
`poster_ip` varchar(40) COLLATE utf8_bin NOT NULL DEFAULT '',
`post_time` int(11) unsigned NOT NULL DEFAULT '0',
`post_approved` tinyint(1) unsigned NOT NULL DEFAULT '1',
`post_reported` tinyint(1) unsigned NOT NULL DEFAULT '0',
`enable_bbcode` tinyint(1) unsigned NOT NULL DEFAULT '1',
`enable_smilies` tinyint(1) unsigned NOT NULL DEFAULT '1',
`enable_magic_url` tinyint(1) unsigned NOT NULL DEFAULT '1',
`enable_sig` tinyint(1) unsigned NOT NULL DEFAULT '1',
`post_username` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',
`post_subject` blob,
`post_text` mediumtext COLLATE utf8_bin NOT NULL,
`post_checksum` varchar(32) COLLATE utf8_bin NOT NULL DEFAULT '',
`post_attachment` tinyint(1) unsigned NOT NULL DEFAULT '0',
`bbcode_bitfield` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',
`bbcode_uid` varchar(8) COLLATE utf8_bin NOT NULL DEFAULT '',
`post_postcount` tinyint(1) unsigned NOT NULL DEFAULT '1',
`post_edit_time` int(11) unsigned NOT NULL DEFAULT '0',
`post_edit_reason` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',
`post_edit_user` mediumint(8) unsigned NOT NULL DEFAULT '0',
`post_edit_count` smallint(4) unsigned NOT NULL DEFAULT '0',
`post_edit_locked` tinyint(1) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`post_id`),
KEY `forum_id` (`forum_id`),
KEY `topic_id` (`topic_id`),
KEY `poster_ip` (`poster_ip`),
KEY `poster_id` (`poster_id`),
KEY `post_approved` (`post_approved`),
KEY `post_username` (`post_username`),
KEY `tid_post_time` (`topic_id`,`post_time`) USING HASH
) ENGINE=InnoDB AUTO_INCREMENT=22381 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
as you can see, the last index is "USING HASH" - but when I use show indexes from posts;, thats not showing it
After a quick Google search, I quickly found that InnoDB doesn't support HASH indexes, but still accepts the modifier in table definitions.
SHOW CREATE TABLE may show USING HASH, but SHOW INDEXES will actually show you what index type is being used:
Index_type
The index method used (BTREE, FULLTEXT, HASH, RTREE).
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Ïðèçûâíèê',
description varchar(1000) DEFAULT 'Îïèñàíèå ïåðñîíàæà îòñóòñòâ' at line 64
CREATE TABLE IF NOT EXISTS users (
id_user int(20) unsigned NOT NULL AUTO_INCREMENT,
name varchar(32) DEFAULT NULL,
pass varchar(32) DEFAULT NULL,
email varchar(64) NOT NULL,
ip varchar(20) NOT NULL,
last_ip varchar(20) NOT NULL,
last_time int(11) NOT NULL DEFAULT '0',
ban int(20) NOT NULL DEFAULT '0',
race int(1) NOT NULL,
gender int(1) NOT NULL DEFAULT '1',
ava1 varchar(100) NOT NULL,
ava2 varchar(100) NOT NULL,
ava3 varchar(100) NOT NULL,
token varchar(32) NOT NULL,
gold int(11) NOT NULL DEFAULT '50',
krystal int(11) NOT NULL DEFAULT '0',
zelen int(11) NOT NULL DEFAULT '0',
hp int(11) NOT NULL DEFAULT '100',
exp int(11) NOT NULL DEFAULT '0',
hp_now int(11) NOT NULL DEFAULT '100',
power int(11) NOT NULL DEFAULT '5',
def int(11) NOT NULL DEFAULT '5',
ability int(11) NOT NULL DEFAULT '5',
mass int(11) NOT NULL DEFAULT '5',
skill int(11) NOT NULL DEFAULT '5',
glory int(11) NOT NULL DEFAULT '0',
ref int(11) NOT NULL DEFAULT '0',
battle int(11) NOT NULL DEFAULT '0',
win int(11) NOT NULL DEFAULT '0',
loot int(11) NOT NULL DEFAULT '0',
lost int(11) NOT NULL DEFAULT '0',
damage int(11) NOT NULL DEFAULT '0',
pet int(20) NOT NULL DEFAULT '0',
safe int(11) NOT NULL DEFAULT '0',
safe2 int(11) NOT NULL DEFAULT '0',
safe3 int(11) NOT NULL DEFAULT '0',
safe4 int(11) NOT NULL DEFAULT '0',
woodoo int(11) NOT NULL DEFAULT '0',
woodoo2 int(11) NOT NULL DEFAULT '0',
woodoo3 int(11) NOT NULL DEFAULT '0',
woodoo4 int(11) NOT NULL DEFAULT '0',
house int(11) NOT NULL DEFAULT '0',
cage int(11) NOT NULL DEFAULT '0',
fence int(11) NOT NULL DEFAULT '0',
road int(11) NOT NULL DEFAULT '0',
out int(11) NOT NULL DEFAULT '0',
plant int(11) NOT NULL DEFAULT '0',
time_dozor int(11) NOT NULL DEFAULT '120',
vip int(20) NOT NULL DEFAULT '0',
last_bat int(11) NOT NULL DEFAULT '0',
clan int(11) NOT NULL DEFAULT '0',
clan_stat varchar(64) NOT NULL 'Призывник',
description varchar(1000) DEFAULT 'Описание персонажа отсутствует',
att_description varchar(500) NOT NULL DEFAULT 'Сообщение отсутствует',
bat_timer int(11) NOT NULL DEFAULT '0',
authlevel int(2) NOT NULL DEFAULT '0',
helmet int(20) NOT NULL DEFAULT '0',
necklet int(20) NOT NULL DEFAULT '0',
weapon int(20) NOT NULL DEFAULT '0',
shield int(20) NOT NULL DEFAULT '0',
armor int(20) NOT NULL DEFAULT '0',
read_msg int(1) NOT NULL DEFAULT '1',
kosti_g int(11) NOT NULL DEFAULT '0',
kosti_k int(11) NOT NULL DEFAULT '0',
kosti_g_stat int(11) NOT NULL DEFAULT '0',
kosti_k_stat int(11) NOT NULL DEFAULT '0',
kosti_z_stat int(11) NOT NULL DEFAULT '0',
kosti_win int(11) NOT NULL DEFAULT '0',
kosti_lose int(11) NOT NULL DEFAULT '0',
naper_g int(11) NOT NULL DEFAULT '0',
naper_k int(11) NOT NULL DEFAULT '0',
recd_naper_g_stat int(11) NOT NULL DEFAULT '0',
recd_naper_k_stat int(11) NOT NULL DEFAULT '0',
recd_naper_z_stat int(11) NOT NULL DEFAULT '0',
spend_naper_g_stat int(11) NOT NULL DEFAULT '0',
spend_naper_k_stat int(11) NOT NULL DEFAULT '0',
spend_naper_z_stat int(11) NOT NULL DEFAULT '0',
naper_win int(11) NOT NULL DEFAULT '0',
naper_lose int(11) NOT NULL DEFAULT '0',
mmine int(11) NOT NULL DEFAULT '0',
msglade int(11) NOT NULL DEFAULT '0',
mbglade int(11) NOT NULL DEFAULT '0',
mpick int(11) NOT NULL DEFAULT '0',
mglass int(11) NOT NULL DEFAULT '0',
mhelmet int(11) NOT NULL DEFAULT '0',
mpicks int(11) NOT NULL DEFAULT '0',
mglasss int(11) NOT NULL DEFAULT '0',
mhelmets int(11) NOT NULL DEFAULT '0',
mflash int(11) NOT NULL DEFAULT '0',
mpow int(11) NOT NULL DEFAULT '0',
mdef int(11) NOT NULL DEFAULT '0',
mabi int(11) NOT NULL DEFAULT '0',
mskil int(11) NOT NULL DEFAULT '0',
mwork int(11) NOT NULL DEFAULT '0',
mper int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (id_user)
) ENGINE=MyISAM DEFAULT CHARSET=cp1251 ;
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'N'Ïðèçûâíèê',
description varchar(1000) CHARACTER SET utf8 NOT NULL DEFAULT' at line 64
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT NULL,
ip varchar(20) DEFAULT NOT NULL,
last_ip varchar(20) CHARACT' at line 16
1067 - Invalid default value for 'clan_stat'
Try specifying a character set:
description varchar(1000) CHARACTER SET utf8 DEFAULT 'Описание персонажа отсутствует',
I'm going off of this example from the MySQL documentaion:
11.1.3. String Type Overview
CREATE TABLE t
(
c1 VARCHAR(20) CHARACTER SET utf8,
c2 TEXT CHARACTER SET latin1 COLLATE latin1_general_cs
);
As far as I know, you'll have to set that for each of your varchar columns.
Here's an example SQLFiddle showing this in action: http://sqlfiddle.com/#!2/e4cc6/1
Alternatively, you might just be able to prefix your string with N:
description varchar(1000) DEFAULT N'Описание персонажа отсутствует'
And here's an example of that: http://sqlfiddle.com/#!2/e6658/1
I have 3 tables that they can be on 1table. What is the best performance for its design?
I need a fast database on search and read, not on insert.
These 3 tables will be read too more than be written
These 3 tables have more than 5 millions records
Most of the fields that are available in this table "p_apartmentbuy" are used in the search clause query (they have been indexed) And include some fields that are shown in the search result
The fields in this table "p_apartmentbuydetail" aren't used in search clause
"pf_contact" table will be used to show on some search result and usually
some columns are null
And what is differences between a "keyname with several indexes" and "several keynames with one index for each one" (like attachment photo).
Relations between tables:
p_apartmentbuy.id = p_apartmentbuydetail.p_apartmentbuy_id (1:1)
pf_contact.id = p_apartmentbuydetail.pf_contact_id (1:1)
CREATE TABLE `p_apartmentbuy` (
`id` mediumint(7) unsigned NOT NULL AUTO_INCREMENT,
`dateadd` int(10) unsigned NOT NULL DEFAULT '0',
`sqm` smallint(5) unsigned NOT NULL DEFAULT '0',
`age` tinyint(2) unsigned NOT NULL DEFAULT '0',
`price` bigint(12) unsigned NOT NULL DEFAULT '0',
`pricemeter` int(10) unsigned NOT NULL DEFAULT '0',
`bedroom` tinyint(1) unsigned NOT NULL DEFAULT '0',
`parking` tinyint(1) unsigned NOT NULL DEFAULT '0',
`storage` tinyint(1) unsigned NOT NULL DEFAULT '0',
`elevator` tinyint(1) unsigned NOT NULL DEFAULT '0',
`describe` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT ' ',
`featured` tinyint(1) unsigned NOT NULL DEFAULT '0',
`pf_source_id` tinyint(1) unsigned NOT NULL DEFAULT '0',
`l_location_id` smallint(5) unsigned NOT NULL DEFAULT '0',
`l_city_id` smallint(4) unsigned NOT NULL DEFAULT '0',
`l_province_id` tinyint(3) unsigned NOT NULL DEFAULT '0',
`pf_status_id` tinyint(1) unsigned NOT NULL DEFAULT '0',
`pf_floor_id` tinyint(2) unsigned NOT NULL DEFAULT '0',
`pf_facing_id` tinyint(2) unsigned NOT NULL DEFAULT '0',
`pf_cabinet_id` tinyint(2) unsigned NOT NULL DEFAULT '0',
`pf_service_id` tinyint(2) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `dateadd` (`dateadd`),
KEY `sqm` (`sqm`),
KEY `age` (`age`),
KEY `price` (`price`),
KEY `bedroom` (`bedroom`),
KEY `parking` (`parking`),
KEY `storage` (`storage`),
KEY `elevator` (`elevator`),
KEY `l_location_id` (`l_location_id`),
KEY `l_city_id` (`l_city_id`),
KEY `l_province_id` (`l_province_id`),
KEY `pricemeter` (`pricemeter`),
FULLTEXT KEY `describe` (`describe`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE `pf_contact` (
`id` mediumint(7) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(30) COLLATE utf8_unicode_ci NOT NULL DEFAULT ' ',
`mobile` bigint(20) unsigned NOT NULL DEFAULT '0',
`telephone` bigint(20) NOT NULL DEFAULT '0',
`telephone2` bigint(20) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE `p_apartmentbuydetail` (
`p_apartmentbuy_id` mediumint(7) unsigned NOT NULL,
`address` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT ' ',
`link` varchar(999) COLLATE utf8_unicode_ci NOT NULL DEFAULT ' ',
`sqmland` smallint(5) unsigned NOT NULL DEFAULT '0',
`floortotal` tinyint(3) unsigned NOT NULL DEFAULT '0',
`floorno` tinyint(3) unsigned NOT NULL DEFAULT '0',
`unitno` tinyint(3) unsigned NOT NULL DEFAULT '0',
`unitperfloor` tinyint(1) unsigned NOT NULL DEFAULT '0',
`remotedoor` tinyint(1) unsigned NOT NULL DEFAULT '0',
`iphone` tinyint(1) unsigned NOT NULL DEFAULT '0',
`trase` tinyint(1) unsigned NOT NULL DEFAULT '0',
`sona` tinyint(1) unsigned NOT NULL DEFAULT '0',
`pool` tinyint(1) unsigned NOT NULL DEFAULT '0',
`jackosi` tinyint(1) unsigned NOT NULL DEFAULT '0',
`renovate` tinyint(1) unsigned NOT NULL DEFAULT '0',
`tel` tinyint(1) unsigned NOT NULL DEFAULT '0',
`water` tinyint(1) unsigned NOT NULL DEFAULT '0',
`gas` tinyint(1) unsigned NOT NULL DEFAULT '0',
`electricity` tinyint(1) unsigned NOT NULL DEFAULT '0',
`pf_kitchen_id` tinyint(1) unsigned NOT NULL DEFAULT '0',
`pf_contact_id` mediumint(7) unsigned NOT NULL DEFAULT '0',
`pf_temperaturesystem_id` tinyint(2) unsigned NOT NULL DEFAULT '0',
`pf_position_id` tinyint(2) unsigned NOT NULL DEFAULT '0',
`prev_id` smallint(8) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`p_apartmentbuy_id`),
KEY `prev_id` (`prev_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
The idea is quite simple: i have three (or more) tables
- master_tbl (id, something, somethingelse)
- tbl2 (id, ....)
- tbl3 (id, ....)
Now what i want is a foreign key relationship, such as tbl3.id would point to tbl2.id and tbl2.id would point to master_tbl.id - all foreign keys are ON UPDATE CASCADE and ON DELETE CASCADE. What I'll get from this is that when I delete a record from tbl2, its tbl3 equivalent will get erased as well, but not master_tbl. When I delete a record from master_tbl, all three tables get erased.
When I try to create the foreign key on tbl3.id->tbl2.id, I get mysql error 150 - can't create table (the tbl2.id->master_tbl.id is already created).
My MySQL version is 5.1.46. Any ideas why this might be?
EDIT: table definitions
smf_members aka master_table
-- Table "smf_members" DDL
CREATE TABLE `smf_members` (
`id_member` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`member_name` varchar(80) NOT NULL DEFAULT '',
`date_registered` int(10) unsigned NOT NULL DEFAULT '0',
`posts` mediumint(8) unsigned NOT NULL DEFAULT '0',
`id_group` smallint(5) unsigned NOT NULL DEFAULT '0',
`lngfile` varchar(255) NOT NULL DEFAULT '',
`last_login` int(10) unsigned NOT NULL DEFAULT '0',
`real_name` varchar(255) NOT NULL DEFAULT '',
`instant_messages` smallint(5) NOT NULL DEFAULT '0',
`unread_messages` smallint(5) NOT NULL DEFAULT '0',
`new_pm` tinyint(3) unsigned NOT NULL DEFAULT '0',
`buddy_list` text NOT NULL,
`pm_ignore_list` varchar(255) NOT NULL DEFAULT '',
`pm_prefs` mediumint(8) NOT NULL DEFAULT '0',
`mod_prefs` varchar(20) NOT NULL DEFAULT '',
`message_labels` text NOT NULL,
`passwd` varchar(64) NOT NULL DEFAULT '',
`openid_uri` text NOT NULL,
`email_address` varchar(255) NOT NULL DEFAULT '',
`personal_text` varchar(255) NOT NULL DEFAULT '',
`gender` tinyint(4) unsigned NOT NULL DEFAULT '0',
`birthdate` date NOT NULL DEFAULT '0001-01-01',
`website_title` varchar(255) NOT NULL DEFAULT '',
`website_url` varchar(255) NOT NULL DEFAULT '',
`location` varchar(255) NOT NULL DEFAULT '',
`icq` varchar(255) NOT NULL DEFAULT '',
`aim` varchar(255) NOT NULL DEFAULT '',
`yim` varchar(32) NOT NULL DEFAULT '',
`msn` varchar(255) NOT NULL DEFAULT '',
`hide_email` tinyint(4) NOT NULL DEFAULT '0',
`show_online` tinyint(4) NOT NULL DEFAULT '1',
`time_format` varchar(80) NOT NULL DEFAULT '',
`signature` text NOT NULL,
`time_offset` float NOT NULL DEFAULT '0',
`avatar` varchar(255) NOT NULL DEFAULT '',
`pm_email_notify` tinyint(4) NOT NULL DEFAULT '0',
`karma_bad` smallint(5) unsigned NOT NULL DEFAULT '0',
`karma_good` smallint(5) unsigned NOT NULL DEFAULT '0',
`usertitle` varchar(255) NOT NULL DEFAULT '',
`notify_announcements` tinyint(4) NOT NULL DEFAULT '1',
`notify_regularity` tinyint(4) NOT NULL DEFAULT '1',
`notify_send_body` tinyint(4) NOT NULL DEFAULT '0',
`notify_types` tinyint(4) NOT NULL DEFAULT '2',
`member_ip` varchar(255) NOT NULL DEFAULT '',
`member_ip2` varchar(255) NOT NULL DEFAULT '',
`secret_question` varchar(255) NOT NULL DEFAULT '',
`secret_answer` varchar(64) NOT NULL DEFAULT '',
`id_theme` tinyint(4) unsigned NOT NULL DEFAULT '0',
`is_activated` tinyint(3) unsigned NOT NULL DEFAULT '1',
`validation_code` varchar(10) NOT NULL DEFAULT '',
`id_msg_last_visit` int(10) unsigned NOT NULL DEFAULT '0',
`additional_groups` varchar(255) NOT NULL DEFAULT '',
`smiley_set` varchar(48) NOT NULL DEFAULT '',
`id_post_group` smallint(5) unsigned NOT NULL DEFAULT '0',
`total_time_logged_in` int(10) unsigned NOT NULL DEFAULT '0',
`password_salt` varchar(255) NOT NULL DEFAULT '',
`ignore_boards` text NOT NULL,
`warning` tinyint(4) NOT NULL DEFAULT '0',
`passwd_flood` varchar(12) NOT NULL DEFAULT '',
`pm_receive_from` tinyint(4) unsigned NOT NULL DEFAULT '1',
PRIMARY KEY (`id_member`),
KEY `member_name` (`member_name`),
KEY `real_name` (`real_name`),
KEY `date_registered` (`date_registered`),
KEY `id_group` (`id_group`),
KEY `birthdate` (`birthdate`),
KEY `posts` (`posts`),
KEY `last_login` (`last_login`),
KEY `lngfile` (`lngfile`(30)),
KEY `id_post_group` (`id_post_group`),
KEY `warning` (`warning`),
KEY `total_time_logged_in` (`total_time_logged_in`),
KEY `id_theme` (`id_theme`)
) ENGINE=InnoDB AUTO_INCREMENT=73 DEFAULT CHARSET=utf8;
cyp_users aka tbl2
-- Table "cyp_users" DDL
CREATE TABLE `cyp_users` (
`id` mediumint(8) unsigned NOT NULL,
`role` varchar(255) NOT NULL DEFAULT 'unregistered',
PRIMARY KEY (`id`),
CONSTRAINT `cyp_users_ibfk_1` FOREIGN KEY (`id`) REFERENCES `smf_members` (`id_member`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
cyp_vip_users aka tbl3
-- Table "cyp_vip_users" DDL
CREATE TABLE `cyp_vip_users` (
`id` mediumint(8) NOT NULL,
`od` date NOT NULL,
`do` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
The ID's of tbl2 and tbl3 are different types.
Foreign Keys need to be of the same type.
tbl2.ID is UNSIGNED
tbl3.ID is SIGNED