[help wanted]:
Contact Details
No response
What is your question?
I've tried to add an asset or a login-passport , I got this⬇️. But when I added the 1st asset, it did successfully. I stopped the other mysql. The only running mysql is oneterm-mysql container.
服务错误: (pymysql.err.IntegrityError) (1452, 'Cannot add or update a child row: a foreign key constraint fails (acl.acl_role_permissions, CONSTRAINT acl_role_permissions_ibfk_1 FOREIGN KEY (rid) REFERENCES acl_roles (id))') [SQL: INSERT INTO acl_role_permissions (deleted_at, deleted, created_at, updated_at, rid, resource_id, group_id, perm_id, app_id) VALUES (%(deleted_at)s, %(deleted)s, %(created_at)s, %(updated_at)s, %(rid)s, %(resource_id)s, %(group_id)s, %(perm_id)s, %(app_id)s)] [parameters: {'deleted_at': None, 'deleted': 0, 'created_at': datetime.datetime(2025, 2, 20, 4, 46, 8, 891969), 'updated_at': None, 'rid': 0, 'resource_id': 36, 'group_id': None, 'perm_id': 8, 'app_id': 4}] (Background on this error at: https://sqlalche.me/e/14/gkpj)
Version
newest
This error is indicating that when you're trying to insert a record into the acl_role_permissions table, the value for rid (role ID) is set to 0, which doesn’t exist in the acl_roles table. In other words, the foreign key constraint is being violated because you're referencing a role that hasn't been created.
Here are a few steps to resolve the issue:
-
Verify the Role Exists:
- Check the
acl_rolestable to see if there is a record withid = 0. Most systems start IDs at 1, so it's likely that no role withid = 0exists.
- Check the
-
Update the Insert Data:
- If
0is not a valid role ID, update your code to use a valid role ID that already exists inacl_rolesor create the necessary role entry if that's what’s expected.
- If
-
Review Your Data Flow:
- Ensure that the process which assigns or passes the role ID (rid) is functioning as intended. There might be a misconfiguration or a bug that sets
ridto0inadvertently.
- Ensure that the process which assigns or passes the role ID (rid) is functioning as intended. There might be a misconfiguration or a bug that sets
-
Check Default Values or Migrations:
- If your application expects a default role, ensure that the default record is properly inserted into the
acl_rolestable during the setup or migration process.
- If your application expects a default role, ensure that the default record is properly inserted into the
By following these steps, you should be able to resolve the foreign key constraint error and proceed with adding your asset or login-passport functionality.