Using MySQL on Windows and getting an error when trying 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 an error present in the subject line (cannot add or update the child line: foreign key failed):
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 might cause the error. I also have a foreign key referencing td_domain_name.domain_id, but I donβt think this should interfere ...
Also, as a workaround (unsuccessful) to this problem (which I am sure can be easily resolved), I tried just doing
td_domain_name left outer join tf_traffic_stats on td_domain_name.domain_name=tf_traffic_stats.domain_name
; however, the number of entries does not match as it should (i.e., the left outer join will not be successful).
Appreciate it!