Author Topic: SQLSTATE[23000] Error - Foreign Key Constraint in thread Table  (Read 436 times)

0 Members and 1 Guest are viewing this topic.

oabm77

  • Jr. Member
  • **
  • Posts: 3
Hello Mibew Team,

I recently installed Mibew Messenger on my server, and everything seemed to work fine. However, when starting a new chat session, I receive the following database error:

Code: [Select]
SQLSTATE[23000]: Integrity constraint violation: 1452
Cannot add or update a child row: a foreign key constraint fails (`chat_visae`.`thread`,
CONSTRAINT `thread_ibfk_1` FOREIGN KEY (`groupid`) REFERENCES `opgroup` (`groupid`))

My Setup:
Mibew Version: 3.6.0
PHP Version: 8.2
Database: 10.11.11-MariaDB
Web Server: Apache

Troubleshooting Steps Taken:
Checked the opgroup table using:

Code: [Select]
SELECT * FROM opgroup;
The table is not empty because I have already created groups and agents.

Questions:
Is this a known bug in recent Mibew versions?
Should Mibew automatically assign a valid groupid to chat threads?
What is the correct way to handle this foreign key constraint issue?

Any help would be greatly appreciated! Thanks in advance.

Best regards,
Omar B.

faf

  • Mibew Staff Member
  • Native
  • *****
  • Posts: 954
    • Mibew Messenger
Re: SQLSTATE[23000] Error - Foreign Key Constraint in thread Table
« Reply #1 on: March 20, 2025, 06:54:40 PM »
Well, I'll take a look at the issue in question. However, I have several questions.

1. Is it a clean installation or you've upgraded from some previous version?

2. Have you downloaded the distribution of Mibew Messenger from our official site?

3. Do you use some third-party plugins or something else, that might affect Mibew Messenger?

You see, there should not be such foreign key in the database schema.

oabm77

  • Jr. Member
  • **
  • Posts: 3
Re: SQLSTATE[23000] Error - Foreign Key Constraint in thread Table
« Reply #2 on: March 20, 2025, 07:26:43 PM »
Hello,

Thank you for your response. Here are my answers to your questions:

It was a clean installation—I did not upgrade from a previous version.
I downloaded Mibew Messenger 3.6.0 directly from the official site.
No third-party plugins or modifications have been installed—it's a default setup.
Regarding the foreign key constraint issue, I checked the database schema, and the thread table does contain a foreign key reference to opgroup(groupid), which seems to be causing the problem.




Would you recommend manually removing this foreign key constraint, or is there another preferred fix?

Thanks for your help!

Best regards,
Omar B.

faf

  • Mibew Staff Member
  • Native
  • *****
  • Posts: 954
    • Mibew Messenger
Re: SQLSTATE[23000] Error - Foreign Key Constraint in thread Table
« Reply #3 on: March 20, 2025, 09:24:47 PM »
Would you recommend manually removing this foreign key constraint, or is there another preferred fix?

Yes, at the moment that's the fix. Delete the foreign key constraint.

As far as I can see, the cause of the issue in question is the difference between MySQL and MariaDB in how they handle inline references specification. While MySQL ignores them, MariaDB (starting from 10.5) attempts to apply  the constraint. Please, bear in mind that Mibew Messenger wasn't tested with MariaDB.

oabm77

  • Jr. Member
  • **
  • Posts: 3
Re: SQLSTATE[23000] Error - Foreign Key Constraint in thread Table
« Reply #4 on: March 20, 2025, 10:22:31 PM »
Thank you for the clarification! I deleted the foreign key constraint as suggested, and it successfully resolved the issue.

I appreciate your support and quick response. Keep up the great work with Mibew!

Best regards,