> For the complete documentation index, see [llms.txt](https://docs.t1ger.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.t1ger.net/resources/t1ger-tuning/troubleshoot/faq.md).

# FAQ

Frequently Asked Questions

{% hint style="success" %}

## Error: 150 “Foreign key constraint is incorrectly formed”

This is an error you are likely to see on if you only have t1ger\_tuning script and is trying to run the database query for t1ger\_tunershops.

1. Open `main.sql` located inside `t1ger_tuning/install`.&#x20;
2. Run this SQL in your database

```lua
-- ONLY RUN THIS IF YOU DO NOT HAVE t1ger_mechanic TABLE ALREADY!!
CREATE TABLE IF NOT EXISTS `t1ger_mechanic` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(100) NOT NULL,
    `job` LONGTEXT NOT NULL DEFAULT ('[]'),
    `blip` LONGTEXT NOT NULL DEFAULT ('[]'),
    `owner` VARCHAR(100) DEFAULT NULL,
    `account` INT(11) NOT NULL DEFAULT 0,
    `employees` LONGTEXT NOT NULL DEFAULT ('[]'),
    `markers` LONGTEXT NOT NULL DEFAULT ('[]'),
    `billing` LONGTEXT NOT NULL DEFAULT ('[]'),
    `for_sale` TINYINT(1) NOT NULL DEFAULT 0,
    `sale_price` INT(11) DEFAULT NULL,
    `type` ENUM('mechanic', 'tuner', 'combined') NOT NULL DEFAULT 'mechanic',
    PRIMARY KEY (`id`)
);
```

3. Refresh the database
4. Then run this SQL in your database:

```sql
DROP TABLE IF EXISTS `t1ger_tunershops`;
CREATE TABLE `t1ger_tunershops` (
    `shop_id` INT(11) NOT NULL, -- FK to t1ger_mechanic.id
    `markup` INT(11) NOT NULL DEFAULT 0, -- % markup for upgrades
    `categories` LONGTEXT NOT NULL DEFAULT ('[]'), -- Available upgrade categories
    `delivery` LONGTEXT DEFAULT NULL, -- Delivery settings as JSON
    `is_combined` TINYINT(1) NOT NULL DEFAULT 0, -- 1 = combined with mechanic
    PRIMARY KEY (`shop_id`),
    FOREIGN KEY (`shop_id`) REFERENCES `t1ger_mechanic`(`id`) ON DELETE CASCADE
);
```

5. Restart your server and you'll be fine.
   {% endhint %}

{% hint style="success" %}

## Failed to insert job

This is an error you are likely to see on `es_extended` when creating shops/jobs in runtime. All you have to do is:

1. Open `createJob.lua` located inside `es_extended/server/modules`. If you do not have a `createJob.lua` file or modules folder, then open `functions.lua` inside `es_extended/server`.
2. Locate the function named: `ESX.CreateJob`.
3. Replace the entire function with the following code:

```lua
--- Create Job at Runtime
--- @param name string
--- @param label string
--- @param grades table
function ESX.CreateJob(name, label, grades)
  local currentResourceName = GetInvokingResource()
  local success = false

  if not name or name == '' then
      print("ERROR",currentResourceName, 'Missing argument `name`')
      return success
  end

  if not label or label == '' then
      print("ERROR",currentResourceName, 'Missing argument `label`')
      return success
  end

  if type(grades) ~= "table" or not next(grades) then
      print("ERROR",currentResourceName, 'Missing argument `grades`')
      return success
  end

  if ESX.DoesJobExist(name, 0) then
      print("ERROR",currentResourceName, 'Job already exists: `%s`', name)
      return success
  end

  local queries = {
      { query = 'INSERT INTO jobs (name, label) VALUES (?, ?)', values = { name, label } }
  }

  for _, grade in pairs(grades) do
      queries[#queries + 1] = {
          query = 'INSERT INTO job_grades (job_name, grade, name, label, salary, skin_male, skin_female) VALUES (?, ?, ?, ?, ?, ?, ?)',
          values = { name, grade.grade, grade.name, grade.label, grade.salary, type(grade.skin_male) == "table" and json.encode(grade.skin_male) or '{}', type(grade.skin_female) == "table" and json.encode(grade.skin_female) or '{}' }
      }
  end

  success = exports.oxmysql:transaction_async(queries)

  if not success then
      print("ERROR", currentResourceName, 'Failed to insert one or more grades for job: `%s`', name)
      return success
  end

  local job = { name = name, label = label, grades = {} }
  for _, v in pairs(grades) do
      job.grades[tostring(v.grade)] = { job_name = name, grade = v.grade, name = v.name, label = v.label, salary = v.salary, skin_male = v.skin_male or '{}', skin_female = v.skin_female or '{}' }
  end

  ESX.Jobs[name] = job

  print("SUCCESS", currentResourceName, 'Job created successfully: `%s`', name)

  TriggerEvent('esx:jobCreated', name, ESX.Jobs[name])

  return success
end
```

4. Restart your server
   {% endhint %}

***
