I'm trying to setup a table that has 2 foreign keys. I was able to set host_id as a Foreign Key, but I cannot get site_id to be a foreign key in the table SITES_HOSTS.
I get mysql error 1005 errno 121
I'm using the MySQL Query Browser when I'm doing this, because I'm not good enough to use the command line, but the app shows me its doing this
ALTER TABLE db_special
.sites_hosts
ADD CONSTRAINT site_id
FOREIGN KEY site_id
(site_id
)
REFERENCES sites
(id
)
ON DELETE RESTRICT
ON UPDATE RESTRICT;
Here are my tables
[B]SITES[/B]
+-------------+---------------------+------+-----+---------------------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| title | varchar(100) | NO | | | |
| description | longtext | YES | | NULL | |
| url | varchar(150) | YES | | NULL | |
| status | tinyint(3) unsigned | NO | | | |
| pubdate | timestamp | NO | | CURRENT_TIMESTAMP | |
| updated | timestamp | NO | | 0000-00-00 00:00:00 | |
| subtitle | varchar(100) | YES | | NULL | |
| sitetype_id | int(10) unsigned | NO | MUL | | |
+-------------+---------------------+------+-----+---------------------+----------------+
[B]HOSTS[/B]
+---------+---------------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------------------+------+-----+-------------------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| title | varchar(100) | NO | | | |
| status | tinyint(3) unsigned | NO | | | |
| pubdate | timestamp | NO | | CURRENT_TIMESTAMP | |
+---------+---------------------+------+-----+-------------------+----------------+
[B]SITES_HOSTS[/B]
+---------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| site_id | int(10) unsigned | NO | | | |
| host_id | int(10) unsigned | NO | MUL | | |
+---------+------------------+------+-----+---------+----------------+