iLLeniumStudios / illenium-appearance

fivem-appearance for qb-core and ESX framework, packed with a lot of features
MIT License
251 stars 227 forks source link

Problems deleting character from multicharacter menu #241

Closed titicarabina closed 1 year ago

titicarabina commented 1 year ago

[ script:oxmysql] Error: qb-core was unable to execute a transaction! [ script:oxmysql] Cannot delete or update a parent row: a foreign key constraint fails (rcdesign_vamos.player_outfit_codes, CONSTRAINT FK_player_outfit_codes_player_outfits FOREIGN KEY (outfitid) REFERENCES player_outfits (id))

I get this error every time i am trying to delete a character that has an outfit code . Can you please check ? Thank you! I am using QBCore

TheiLLeniumStudios commented 1 year ago

Hi @titicarabina . Thank you for reporting the issue. Unfortunately, due to proper database constraints, qb-multicharacter needs to be modified. You can replace the qb-multicharacter:server:deleteCharacter event with this one in server/server.lua and it should fix the issue. I will also add it to the multicharacter docs

RegisterNetEvent('qb-multicharacter:server:deleteCharacter', function(citizenid)
    local src = source
    local Player = QBCore.Functions.GetPlayer(src)
    local outfits = MySQL.query.await("SELECT * FROM player_outfits WHERE citizenid = ?", {citizenid})
    for i = 1, #outfits, 1 do
        MySQL.query.await("DELETE FROM player_outfit_codes WHERE id = ?", {outfits[i].id})
    end
    Wait(1000)
    QBCore.Player.DeleteCharacter(src, citizenid)
    TriggerClientEvent('QBCore:Notify', src, Lang:t("notifications.char_deleted") , "success")
end)
TheiLLeniumStudios commented 1 year ago

In order to keep compatibility and reduce the amount of modifications, I have removed the foreign key constraint in https://github.com/iLLeniumStudios/illenium-appearance/commit/ac41c1eef0b840a6676945b04c911a22bbdb1ecc

So feel free to delete the table and recreate it again using the new SQL and you should not need the above modifications