Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
1.2k views
in Q2A Core by
edited by
I just upgraded the site http://socialpollination.biz/answers/ to v1.2beta to address the WordPress AJAX issue. However, after a few errors with the upgrade, I decided to start with a clean database. I've reinstalled the tables with a new prefix, and integrated the WP users. However, when attempting to ask a question, I get the following error.

Here is the specific code:

Question2Answer query failed:

INSERT INTO qa2_posts (categoryid, type, parentid, userid, cookieid, createip, title, content, tags, notify, created) VALUES (NULL, _utf8 'Q', NULL, _utf8 '7', NULL, INET_ATON(_utf8 '67.78.24.210'), _utf8 'Please work today', _utf8 'Please please please work this time.', _utf8 'please,work,this,time', _utf8 '@', NOW())

Error 1452: Cannot add or update a child row: a foreign key constraint fails (`thescra4_socialpol`.`qa2_posts`, CONSTRAINT `qa2_posts_ibfk_1` FOREIGN KEY (`userid`) REFERENCES `qa2_users` (`userid`) ON DELETE SET NULL)

It appears to be tied to the WordPress user tables integration, since I am able to ask a question when disabling that functionality.
by
I also noticed this thread: http://www.question2answer.org/qa/1643/1-2-beta-1-external-users-error  where they mentioned an issue with BlueHost. That is the current host for the site. Not sure if it matters, but I thought I'd include that.
by
I have the same issue but I can't fix it. I do not use wordpress.

2 Answers

0 votes
by
I figured out my issue. I had to include the following code: include_once('../wp-config.php');
include_once('../wp-load.php');
include_once('../wp-includes/wp-db.php');
global $wpdb;

on the following files
qa-external-users.php
qa-config.php
qa-theme-base.php

prior to the database install.
0 votes
by
This would happen if you install the database with internal user management, and then change later to single sign-on integration. In other words, you need to set QA_EXTERNAL_USERS before installing the database, so that it doesn't create a qa_users (or in your case, qa2_users) table, with corresponding foreign key constraints.
...