Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
936 views
in Q2A Core by

two QA sites with one user database, login and login out are ok.  But when adding a new post at the second QA site(share the first QA site' user database), error:

Question2Answer query failed:

INSERT INTO juku_posts (categoryid, type, parentid, userid, cookieid, createip, title, content, format, tags, notify, created) VALUES (NULL, _utf8 'Q', NULL, _utf8 '1', NULL, INET_ATON(_utf8 '125.122.87.4'), _utf8 'I\'ll perish you represented the moon!', _utf8 '我要代表月亮消灭你!', _utf8 '', _utf8 '', _utf8 '@', NOW())

Error 1452: Cannot add or update a child row: a foreign key constraint fails (`cookboo1_wanyuwang`.`juku_posts`, CONSTRAINT `juku_posts_ibfk_1` FOREIGN KEY (`userid`) REFERENCES `juku_users` (`userid`) ON DELETE SET NULL)

 

the first QA site:

define('QA_MYSQL_TABLE_PREFIX', 'qa_');

define('QA_MYSQL_USERS_PREFIX', 'qa_');

define('QA_COOKIE_DOMAIN', '.damain.com');

the second QA site:

define('QA_MYSQL_TABLE_PREFIX', 'juku_');

define('QA_MYSQL_USERS_PREFIX', 'qa_');

define('QA_COOKIE_DOMAIN', '.damain.com');

1 Answer

+1 vote
by

I think the problem is that you added the definition of QA_MYSQL_USERS_PREFIX after installing the site that gave this error. This won't work because its database was already set up with relationships between the tables, including its own user tables.

To solve the problem, either (a) delete the juku_* tables and start again, (b) change the foreign key definition that caused this problem to refer to the qa_users table instead of juku_users (also need to simliarly fix tables juku_uservotes and juku_userlimits, or (c) remove the foreign keys completely, since they're only their for integrity checking and aren't required for Q2A to work.

Please let us know if one of the above solves the problem.

by
Thank you very much! worked!
The right steps to setup a meta QA site:
1、upload QA scripts files;
2、modify qa-config.php(important!), define('QA_MYSQL_TABLE_PREFIX', 'qameta_');(qameta site database PREFIX).define('QA_MYSQL_USERS_PREFIX', 'qa_');
3、set up through http://qameta.com/index.php, done.
by
Uhmm, my single sign no work!!
Abcute or gidgreen, Would you paste your full example code from qa-external-users.php , here please?  thanks for your help!
...