Hi all,
Using MySQL on Windows OS, and am getting an error upon attempting to create a foreign key between two tables:
CREATE TABLE tf_traffic_stats (
domain_name char(100) NOT NULL,
session_count int(11) NULL,
search_count int(11) NULL,
click_count int(11) NULL,
revenue float NULL,
rpm float NULL,
cpc float NULL,
traffic_date date NOT NULL DEFAULT '0000-00-00',
PRIMARY KEY(domain_name,traffic_date))
and
CREATE TABLE td_domain_name (
domain_id int(10) UNSIGNED AUTO_INCREMENT NOT NULL,
domain_name char(100) NOT NULL,
update_date date NOT NULL,
PRIMARY KEY(domain_id))
The following statement gives me the error present in the subject line (cannot add or update a child row: a foreign key constraint fails):
ALTER TABLE td_domain_name
ADD CONSTRAINT FK_domain_name
FOREIGN KEY(domain_name)
REFERENCES tf_traffic_stats(domain_name)
ON DELETE RESTRICT
ON UPDATE RESTRICT
Can someone point me in the right direction of what may be causing the error. I also have a foreign key referencing td_domain_name.domain_id, but I don't think this should be interfering...
Also, as a workaround (failed) to this issue (which I'm sure can be easily resolved), I've tried simply performing a
td_domain_name left outer join tf_traffic_stats on td_domain_name.domain_name=tf_traffic_stats.domain_name
; however, the number of records do not match up as they should (i.e., left outer join not successful).
Appreciate it!