Skip to content

Commit

Permalink
Fixing the incorrect table name in server.lua and updating the README…
Browse files Browse the repository at this point in the history
… with the solution for the properties.sql import issue. (#122)

* Readme update: About resolving the 'Foreign key constraint is incorrectly formed' Issue

* Fix database query: Update table name from apartments to properties
  • Loading branch information
Ruby-LK authored Aug 27, 2023
1 parent a7c64c3 commit adcee6e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,22 @@ end)

2. From a client or server console run the `migrateapartments` command to automatically convert all apartments from qb-apartments. It will print a message to the console once complete.

## Resolving the "Foreign key constraint is incorrectly formed" Issue

If you come across an error such as `Foreign key constraint is incorrectly formed` while importing the `properties.sql` into your database, follow these steps to fix it.

1. Open your database in HeidiSQL.
2. Right-click on your database name and select "Edit."
3. Locate the database collation setting take a note of it.
4. You will need to format the `properties.sql` file to match your database collation.

If your database collation is set to `utf8mb4_general_ci`, modify the last line of the `properties.sql` file using VSCode or in HeidiSQL's query tab to the following:

```sql
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
```
This adjustment ensures that `properties.sql` file's character set and collation match that of your database, effectively resolving the issue.

## Item Limits System

1. Choose an item you want to limit under `Config.Furniture` in under `shared/config.lua`
Expand Down Expand Up @@ -325,4 +341,4 @@ ensure fivem-freecam
* [Byte Labs Project](https://github.com/Byte-Labs-Project)
* [Project Sloth Team](https://discord.gg/projectsloth)
* [K4MB1](https://www.k4mb1maps.com/)
* [Candrex](https://github.com/CandrexDev)
* [Candrex](https://github.com/CandrexDev)
2 changes: 1 addition & 1 deletion server/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ lib.callback.register("ps-housing:cb:GetOwnedApartment", function(source, cid)
else
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local result = MySQL.query.await('SELECT * FROM apartments WHERE owner_citizenid = ? AND apartment IS NOT NULL AND apartment <> ""', { Player.PlayerData.citizenid })
local result = MySQL.query.await('SELECT * FROM properties WHERE owner_citizenid = ? AND apartment IS NOT NULL AND apartment <> ""', { Player.PlayerData.citizenid })
if result[1] ~= nil then
return result[1]
end
Expand Down

0 comments on commit adcee6e

Please sign in to comment.