MySQL: referencing foreign keys - mysql

I am trying to reference a foreign key to its parent key in mysql and i get an awkward error.
I have tried the following.
ALTER TABLE `website`
ADD CONSTRAINT `website_cms_fk1` FOREIGN KEY (`cms_id`) REFERENCES `cms_technology` (`ID`);
also
ALTER TABLE website ADD FOREIGN KEY (cms_id) REFERENCES cms_technology (ID)
And I get the following error.
*#1005 - Can't create table 'script.#sql-5203_110b8ba' (errno: 150)*
The following is my tables
CREATE TABLE IF NOT EXISTS `cms_technology` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`cms_name` varchar(250) NOT NULL DEFAULT '',
`cms_description` varchar(250) NOT NULL DEFAULT '',
PRIMARY KEY (`ID`)
);
INSERT INTO `cms_technology` (`ID`, `cms_name`, `cms_description`) VALUES
(1, 'Wordpress', 'WordPress › Blog Tool, Publishing Platform, and CMS');
CREATE TABLE IF NOT EXISTS `website` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`website_url` varchar(60) NOT NULL DEFAULT '',
`website_ip` varchar(20) NOT NULL DEFAULT '',
`website_title` varchar(250) NOT NULL DEFAULT '',
`website_status` varchar(10) NOT NULL DEFAULT '',
`website_scanned` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`website_response` int(3) NOT NULL DEFAULT '0',
`cms_id` int(5) NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`)
);
INSERT INTO `website` (`ID`, `website_url`, `website_ip`, `website_title`, `website_status`, `website_scanned`, `website_response`, `website_cms`) VALUES
(1, 'http://www.wpbeginner.com/', '', '', '', '0000-00-00 00:00:00', 0, 0);
What im I doing wrong?

you need to change the data type of the of column cms_ID from table website in order to reference table cms_technology. The properties of the to columns must be the same.
CREATE TABLE IF NOT EXISTS `website` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`website_url` varchar(60) NOT NULL DEFAULT '',
`website_ip` varchar(20) NOT NULL DEFAULT '',
`website_title` varchar(250) NOT NULL DEFAULT '',
`website_status` varchar(10) NOT NULL DEFAULT '',
`website_scanned` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`website_response` int(3) NOT NULL DEFAULT '0',
`cms_id` bigint(20) unsigned NOT NULL, -- <<== HERE
PRIMARY KEY (`ID`)
);
SQLFiddle Demo

I was missing the KEY cms_id (cms_id)
CREATE TABLE IF NOT EXISTS `website` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`website_url` varchar(60) NOT NULL DEFAULT '',
`website_ip` varchar(20) NOT NULL DEFAULT '',
`website_title` varchar(250) NOT NULL DEFAULT '',
`website_status` varchar(10) NOT NULL DEFAULT '',
`website_scanned` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`website_response` int(3) NOT NULL DEFAULT '0',
`cms_id` bigint(20) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`),
KEY `cms_id` (`cms_id`)
);
ALTER TABLE `website`
ADD CONSTRAINT `website_cms_fk1` FOREIGN KEY (`cms_id`) REFERENCES `cms_technology` (`ID`);

Related

Cant create a relation in mysql - Error creating foreign key on id_produk (check data types)

here is my table :
CREATE TABLE `pesanan` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`ref_number` varchar(50) NOT NULL DEFAULT '',
`id_produk` int(11) NOT NULL,
`id_user` int(11) NOT NULL,
`qty` int(11) NOT NULL,
`total` varchar(50) NOT NULL DEFAULT '',
`tanggal` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1;
i want to create a relation of id_produk to table produk.id and id_user to user.id, here is the other table :
CREATE TABLE `produk` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`id_kategori` int(11) NOT NULL,
`status` varchar(10) NOT NULL DEFAULT '',
`slug` varchar(100) NOT NULL DEFAULT '',
`judul` varchar(100) NOT NULL DEFAULT '',
`harga` varchar(10) DEFAULT '',
`target` int(11) DEFAULT NULL,
`desc` text,
`cover` varchar(100) DEFAULT NULL,
`tanggal` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=latin1;
and user table
CREATE TABLE `user` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`suspended` int(11) DEFAULT NULL,
`level` varchar(11) DEFAULT NULL,
`nama` varchar(100) DEFAULT NULL,
`email` varchar(100) DEFAULT NULL,
`password` varchar(100) DEFAULT NULL,
`alamat` text,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=latin1;
when i try to relation it , it give me this error :
Error creating foreign key on id_produk (check data types)
The columns should have the exact same data type in both tables. In your case in the "produk" and "user" tables they are unsigned, which means they go from 0 to 4294967295 but in the "pesanan" table they are signed which means they go from -2147483648 to 2147483647. See more here.
If the server allowed you to create such foreign keys, it would possibly create situations where, for example, a user is added with and ID of 2147483648 that cannot ever be referenced in the "pesanan" table.
You should change the "id_produk" and "id_user" columns in the "pesanan" table to be unsigned.

MySQL: errno: 105 can't create table

I wanted to make a database exactly as below:
So I wanted to define the primary and foreign keys for each table.
Based on this answer, I saw that:
"city" table has 1 PK (ID) and 1 FK (countrycode)
"countrylanguage" table has 2 PK (Language and countrycode) and 1 FK
(countrycode)
"country" table has 1 PK (Code)
So I tried to make some magic on a "pre-heated" code:
CREATE TABLE `City` (
`ID` int(11) NOT NULL,
`Name` varchar(35) NOT NULL ,
`CountryCode` varchar(3) NOT NULL DEFAULT '',
`District` varchar(20) NOT NULL ,
`Population` int(11) NOT NULL ,
PRIMARY KEY(`ID`) ,
FOREIGN KEY(`CountryCode`) REFERENCES `Country`(`Code`)
) ;
CREATE TABLE `CountryLanguage` (
`CountryCode` varchar(3) NOT NULL DEFAULT '',
`Language` varchar(30) NOT NULL ,
`IsOfficial` varchar(30) NOT NULL ,
`Percentage` float(4,1) NOT NULL ,
PRIMARY KEY(`Language`),
FOREIGN KEY(`CountryCode`) REFERENCES `Country`(`Code`)
) ;
CREATE TABLE `Country` (
`Code` varchar(3) NOT NULL DEFAULT '',
`Name` varchar(52) NOT NULL DEFAULT '',
`Continent` varchar(63),
`Region` varchar(26) NOT NULL DEFAULT '',
`SurfaceArea` float(10,2) NOT NULL DEFAULT '0.00',
`IndepYear` smallint(6) DEFAULT NULL,
`Population` int(11) NOT NULL DEFAULT '0',
`LifeExpectancy` float(3,1) DEFAULT NULL,
`GNP` float(10,2) DEFAULT NULL,
`GNPOld` float(10,2) DEFAULT NULL,
`LocalName` varchar(45) NOT NULL DEFAULT '',
`GovernmentForm` varchar(45) NOT NULL DEFAULT '',
`HeadOfState` varchar(60) DEFAULT NULL,
`Capital` int(11) DEFAULT NULL,
`Code2` varchar(2) NOT NULL DEFAULT '',
PRIMARY KEY(`Code`)
) ;
but my good ol' mysql command line client has the same ERROR 1005 thing twice, and says that it can't create tables 'test.city' and 'test.countrylanguage'
with the errno:150 thingy as an explanation.
So I searched a bit around here and I found some answers regarding to table elements not having the same type/parameter (f.e. INT(2) to INT(2) NOT NULL). As fas as I could see, Nothing like this happens here.
What is my coffee-drained brain missing here?
Thank you for your time in advance.
CREATE TABLE Country first, then CREATE TABLE City, and CREATE TABLE CountryLanguage, since TABLE Country is referenced by the other two tables.
wrong create sequnce you should create firts Country because City and CountryLanguage refer to country table
CREATE TABLE `Country` (
`Code` varchar(3) NOT NULL DEFAULT '',
`Name` varchar(52) NOT NULL DEFAULT '',
`Continent` varchar(63),
`Region` varchar(26) NOT NULL DEFAULT '',
`SurfaceArea` float(10,2) NOT NULL DEFAULT '0.00',
`IndepYear` smallint(6) DEFAULT NULL,
`Population` int(11) NOT NULL DEFAULT '0',
`LifeExpectancy` float(3,1) DEFAULT NULL,
`GNP` float(10,2) DEFAULT NULL,
`GNPOld` float(10,2) DEFAULT NULL,
`LocalName` varchar(45) NOT NULL DEFAULT '',
`GovernmentForm` varchar(45) NOT NULL DEFAULT '',
`HeadOfState` varchar(60) DEFAULT NULL,
`Capital` int(11) DEFAULT NULL,
`Code2` varchar(2) NOT NULL DEFAULT '',
PRIMARY KEY(`Code`)
) ;
CREATE TABLE `City` (
`ID` int(11) NOT NULL,
`Name` varchar(35) NOT NULL ,
`CountryCode` varchar(3) NOT NULL DEFAULT '',
`District` varchar(20) NOT NULL ,
`Population` int(11) NOT NULL ,
PRIMARY KEY(`ID`) ,
FOREIGN KEY(`CountryCode`) REFERENCES `Country`(`Code`)
) ;
CREATE TABLE `CountryLanguage` (
`CountryCode` varchar(3) NOT NULL DEFAULT '',
`Language` varchar(30) NOT NULL ,
`IsOfficial` varchar(30) NOT NULL ,
`Percentage` float(4,1) NOT NULL ,
PRIMARY KEY(`Language`),
FOREIGN KEY(`CountryCode`) REFERENCES `Country`(`Code`)
) ;

SQL {setCharset} AUTO_INCREMENT=1' at line 1

DROP TABLE IF EXISTS `{DB_TABLE_PREFIX}broadcast`;
#[QUERY]
CREATE TABLE `{DB_TABLE_PREFIX}broadcast` (
`bid` mediumint(8) NOT NULL auto_increment,
`sortid` mediumint(8) NOT NULL default '0',
`content` varchar(255) NOT NULL default '',
`gourl` varchar(255) NOT NULL default '#',
PRIMARY KEY (`bid`)
) TYPE=MyISAM {setCharset} AUTO_INCREMENT=1 ;
#[QUERY]
DROP TABLE IF EXISTS `{DB_TABLE_PREFIX}items`;
#[QUERY]
CREATE TABLE `{DB_TABLE_PREFIX}items` (
`itemid` mediumint(8) unsigned NOT NULL auto_increment,
`uid` mediumint(8) unsigned NOT NULL default '0',
`account` varchar(15) NOT NULL default '',
`content` varchar(255) NOT NULL default '',
`dateline` int(10) unsigned NOT NULL default '0',
`digg` mediumint(8) unsigned NOT NULL default '0',
`reply` mediumint(5) unsigned NOT NULL default '0',
PRIMARY KEY (`itemid`),
KEY `uid` (`uid`)
) TYPE=MyISAM {setCharset} AUTO_INCREMENT=1 ;
#[QUERY]
DROP TABLE IF EXISTS `{DB_TABLE_PREFIX}reply`;
#[QUERY]
CREATE TABLE `{DB_TABLE_PREFIX}reply` (
`rid` mediumint(8) NOT NULL auto_increment,
`replyto` mediumint(8) unsigned NOT NULL default '0',
`uid` mediumint(8) NOT NULL default '0',
`account` varchar(15) NOT NULL default '',
`content` varchar(255) NOT NULL default '',
`dateline` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`rid`),
KEY `uid` (`uid`),
KEY `replyto` (`replyto`)
) TYPE=MyISAM {setCharset} AUTO_INCREMENT=1 ;
#[QUERY]
DROP TABLE IF EXISTS `{DB_TABLE_PREFIX}setting`;
#[QUERY]
CREATE TABLE `{DB_TABLE_PREFIX}setting` (
`setname` varchar(255) NOT NULL default '',
`data` text NOT NULL,
PRIMARY KEY (`setname`)
) TYPE=MyISAM {setCharset} ;
I try to import this to mysql database and receive this error
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 '{setCharset} AUTO_INCREMENT=1' at line 1
Did I did miss something? Please help me out!
Try this:
CREATE TABLE `broadcast` (
`bid` mediumint(8) NOT NULL auto_increment,
`sortid` mediumint(8) NOT NULL default '0',
`content` varchar(255) NOT NULL default '',
`gourl` varchar(255) NOT NULL default '#',
PRIMARY KEY (`bid`)
) TYPE=MyISAM AUTO_INCREMENT=50 ;
The curly brackets were just for explanation as you refereed the syntax from some other source.
Replace
TYPE=MyISAM
by
ENGINE=MYISAM
Try this, I have used table prefix as "t_"
DROP TABLE IF EXISTS `t_broadcast`;
CREATE TABLE `t_broadcast` (
`bid` MEDIUMINT(8) NOT NULL AUTO_INCREMENT,
`sortid` MEDIUMINT(8) NOT NULL DEFAULT '0',
`content` VARCHAR(255) NOT NULL DEFAULT '',
`gourl` VARCHAR(255) NOT NULL DEFAULT '#',
PRIMARY KEY (`bid`)
) ENGINE=MYISAM;
DROP TABLE IF EXISTS `t_items`;
CREATE TABLE `t_items` (
`itemid` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT,
`uid` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0',
`account` VARCHAR(15) NOT NULL DEFAULT '',
`content` VARCHAR(255) NOT NULL DEFAULT '',
`dateline` INT(10) UNSIGNED NOT NULL DEFAULT '0',
`digg` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0',
`reply` MEDIUMINT(5) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`itemid`),
KEY `uid` (`uid`)
) ENGINE=MYISAM;
DROP TABLE IF EXISTS `t_reply`;
CREATE TABLE `t_reply` (
`rid` MEDIUMINT(8) NOT NULL AUTO_INCREMENT,
`replyto` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0',
`uid` MEDIUMINT(8) NOT NULL DEFAULT '0',
`account` VARCHAR(15) NOT NULL DEFAULT '',
`content` VARCHAR(255) NOT NULL DEFAULT '',
`dateline` INT(10) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`rid`),
KEY `uid` (`uid`),
KEY `replyto` (`replyto`)
) ENGINE=MYISAM;
DROP TABLE IF EXISTS `t_setting`;
CREATE TABLE `t_setting` (
`setname` VARCHAR(255) NOT NULL DEFAULT '',
`data` TEXT NOT NULL,
PRIMARY KEY (`setname`)
) ENGINE=MYISAM ;

#1005 - Can't create table errno: 150 Magento

I am trying to create a new table for magento and I am trying to reference existing magento tables. From what I googled, the problem that I am getting can be 1 of the 2 issues.
The FK must have a index
The PK must exist before the FK can reference
In both cases, I believe I did both of these correctly. Below is existing table schemas
ALREADY EXISTING TABLES BEING REFERENCED
CREATE TABLE IF NOT EXISTS `core_store` (
`store_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`code` varchar(32) NOT NULL DEFAULT '',
`website_id` smallint(5) unsigned DEFAULT '0',
`group_id` smallint(5) unsigned NOT NULL DEFAULT '0',
`name` varchar(255) NOT NULL,
`sort_order` smallint(5) unsigned NOT NULL DEFAULT '0',
`is_active` tinyint(1) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`store_id`),
UNIQUE KEY `code` (`code`),
KEY `FK_STORE_WEBSITE` (`website_id`),
KEY `is_active` (`is_active`,`sort_order`),
KEY `FK_STORE_GROUP` (`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Stores' AUTO_INCREMENT=9 ;
CREATE TABLE IF NOT EXISTS `admin_user` (
`user_id` mediumint(9) unsigned NOT NULL AUTO_INCREMENT,
`firstname` varchar(32) NOT NULL DEFAULT '',
`lastname` varchar(32) NOT NULL DEFAULT '',
`email` varchar(128) NOT NULL DEFAULT '',
`username` varchar(40) NOT NULL DEFAULT '',
`password` varchar(100) NOT NULL DEFAULT '',
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`modified` datetime DEFAULT NULL,
`logdate` datetime DEFAULT NULL,
`lognum` smallint(5) unsigned NOT NULL DEFAULT '0',
`reload_acl_flag` tinyint(1) NOT NULL DEFAULT '0',
`is_active` tinyint(1) NOT NULL DEFAULT '1',
`extra` text,
`failures_num` smallint(6) NOT NULL DEFAULT '0',
`first_failure` datetime DEFAULT NULL,
`lock_expires` datetime DEFAULT NULL,
PRIMARY KEY (`user_id`),
UNIQUE KEY `UNQ_ADMIN_USER_USERNAME` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Users' AUTO_INCREMENT=25 ;
Table I am trying to create
CREATE TABLE `oro_dashboard`
( `id` int unsigned NOT NULL,
`name` varchar(255) NOT NULL default '',
`description` varchar(64) NOT NULL default '',
`created_by` int unsigned NOT NULL default '0',
`created_at` date,
`layout` varchar(255) NOT NULL default '',
`default_store_id` int,
PRIMARY KEY (`id`),
KEY `IDX_ORO_DASHBOARD_CREATED_BY` (`created_by`),
CONSTRAINT `FK_ORO_DASHBOARD_CREATED_BY_ADMIN_USER_USER_ID` FOREIGN KEY (`created_by`) REFERENCES `admin_user` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_ORO_DASHBOARD_DEFAULT_STORE_ID_CORE_STORE_STORE_ID` FOREIGN KEY (`default_store_id`) REFERENCES `core_store` (`store_id`) ON DELETE SET NULL ON UPDATE CASCADE )
ENGINE=INNODB charset=utf8 COLLATE=utf8_unicode_ci
In magento, I found there is in deed a table called admin_user that does have a column called user_id. There is a core_store table that does have a column called store_id. and both my columns have INDEXES made.
Does anyone have any clue what the issue maybe ? Below is my error message
#1005 - Can't create table 'db.oro_dashboard' (errno: 150)
It is necessary to have data type to be same for the foreign key and its corresponding parent key. The data type is different of the foreign key and its referencing parent key in your table that is why it is giving an error.
created by is int unsigned while userid is medium int in parent table
same is problem in the second foreign key
reference http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html
When defining foreign keys, the data type must be the same.
You are defining core_store.store_id as smallint(5) unsigned and so the referencing column must be the same: oro_dashboard.default_store_id.
Do also with oro_dashboard.created_by
Final oro_dashboard CREATE TABLE query,
CREATE TABLE `oro_dashboard`
( `id` int unsigned NOT NULL,
`name` varchar(255) NOT NULL default '',
`description` varchar(64) NOT NULL default '',
`created_by` mediumint(9) unsigned NOT NULL default '0',
`created_at` date,
`layout` varchar(255) NOT NULL default '',
`default_store_id` smallint(5) unsigned,
PRIMARY KEY (`id`),
KEY `IDX_ORO_DASHBOARD_CREATED_BY` (`created_by`) ,
CONSTRAINT `FK_ORO_DASHBOARD_CREATED_BY_ADMIN_USER_USER_ID`
FOREIGN KEY (`created_by`)
REFERENCES `admin_user` (`user_id`)
ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_ORO_DASHBOARD_DEFAULT_STORE_ID_CORE_STORE_STORE_ID`
FOREIGN KEY (`default_store_id`)
REFERENCES `core_store` (`store_id`)
ON DELETE SET NULL ON UPDATE CASCADE
)
SQLFIddle Demo
It appears that the column definition for default_store_id does not match core_store.store_id. it should be smallint(5) unsigned in your table. created_by has the same problem, although it did not prevent the table from being created

MySQL foreign key to another foreign key

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