rappasoft / laravel-boilerplate

The Laravel Boilerplate Project - https://laravel-boilerplate.com
https://rappasoft.com
5.59k stars 1.58k forks source link

Integrity constraint violation when permanent deleting user created via social login #967

Closed drjekyll closed 6 years ago

drjekyll commented 6 years ago

Cloud9 development environment with MySQL 5.7.19 Laravel Boilerplate 5.5 - fresh clone from GitHub Install, configure, test basic operation. Add Facebook Socialite provider infromation. Navigate to register, choose Facebook login Login completes and new user is created. Login as admin@admin.com Navigate to user management and delete the just created Facebook user The soft delete works as expected. Go to deleted user and try to permanently delete the user.

SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (c9.social_accounts, CONSTRAINT social_accounts_user_id_foreign FOREIGN KEY (user_id) REFERENCES users (id)) (SQL: delete from users where id = 4)

Stack trace (if that's what you call it in PHP) leads to forceDelete() function in app/Repositories/Backend/Auth/UserRepository.php

Permanent deleting a user created through the regular registration process works as expected.

Regards, mark

rappasoft commented 6 years ago

You're right.

Place $user->providers()->delete(); before the user delete call and it should fix it.

Wrap it in a transaction for good measure.

Will fix on next release.

drjekyll commented 6 years ago

Super! That took care of it. Thanks much.

drjekyll commented 6 years ago

Oops, maybe I shouldn't be the one to close it until after the fix is in. This way others can see it more easily. Sorry if I get the etiquette wrong...

rappasoft commented 6 years ago

Fixed in release in like an hour.

MurukanK commented 6 years ago

An exception occurred while executing 'DELETE FROM AttributeKeys WHERE akID = ?' with params [110]: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (thermote_v58.atEmptySettings, CONSTRAINT FK_ED1BF189B6561A7E FOREIGN KEY (akID) REFERENCES AttributeKeys (akID))

I uninstall my package in concrete5.7 , then this error is occurred, could you give solutions?