Setting up Database
The Game database contains all the game data, such as items, dialogues, perks, etc. The modding pack contains a dump of the game database in SQL format. In this tutorial we are going to use PostreSQL hosted locally on your computer, which the modding tools will connect to.
First download and install PostreSQL from <a alt="https://www.postgresql.org/" href="https://www.postgresql.org/" title="https://www.postgresql.org/">their website</a>. (Do not install version 12, as this might cause a missing column "adsrc" error when you later run the sequences.sql script) You will also want to install the 64-bit PosgreSQL ODBC driver, which you can get from <a alt="https://odbc.postgresql.org/" href="https://odbc.postgresql.org/" title="https://odbc.postgresql.org/">https://odbc.postgresql.org/</a>. After install the database server should be up and running. Then we open pgAdmin (comes with the PostgreSQL package) tool and connect to the server. After connecting to the server we have to create a new database called
ConfigDB (the name is unfortunatley hardcoded into some of the tools). When created add new
uuid-ossp extention to this database.
<img alt="Setting_Up_Database_image1.jpg" src="" />
If you do not have acces to the pgAdmin you can run this via command line using psql.exe (comes with PostgreSQL package) with the following commands.
Note that creating your database through the psql tool will result in stripping out the case sensitivity (ConfigDB becomes configdb). The mod tools do not appear to require precise case for the database name, but other SQL tools (such as running psql from the command line in the example below) might.
After completing first step we use psql.exe or cmd to restore the database from provided dumps.
You will be asked for your database password again. Ideally this command should run with no output of any kind (the -q switch hides all non-errors, and there should be no errors). In your database, there should be now a schema called
modding with 468 tables.
WARNING: This process was changed completely in version 2 of the modding tools. Make sure you have the new sequences.sql file
Some tables use autoincrement to generate IDs for new entries. If you are going to create new dialogues, you are going to need to adjust the initial value for this autoincrement to a value unique for your mod. If you don’t, your mod will clash with any other mods that also failed to set a unique value. To do this, pick an offset (<a alt="//forums.nexusmods.com/index.php?/topic/8510843-register-unique-modding-ids-20/" href="//forums.nexusmods.com/index.php?/topic/8510843-register-unique-modding-ids-20/" title="//forums.nexusmods.com/index.php?/topic/8510843-register-unique-modding-ids-20/">unofficial registry of IDs for modders</a>), then run following command (replace X with your selected offset):
When using PostgreSQL 12 or newer, you will get an error message about "adsrc" column. To fix this error, open sequences.sql in text editor and replace all "adsrc" with "pg_get_expr(ad.adbin, ad.adrelid)", then save file and re-execute command.
(Optional) Inspecting the Database
You can check yourself whether the database has been set up properly by looking at the
START values of the sequences in the
ConfigDB database. The values in the
modding schema should either be equal to values in the cmd output of the first psql.exe command above or a sum of one of these cmd output values and your offset. Similarly, the value in the
public schema should be equal to the value in the cmd output of the second psql.exe command above.
<img alt="47833563-1584964381.png" src="" />
START value = cmd output (20) + offset (69000)
Setting up tools
There are several tools that work with the SQL database. Most of them require you to set up correct registry keys which they read connection information from. To do that, modify file
Tools/!registry/db.reg (you only need to modify the password,
postgres is the default user) and then run it. All of the tools, except the Sandbox editor, use these registry keys. To get the Sandbox to connect, fill in correct connection information in
user.cfg. Sandbox editor also requires an ODBC Driver to use. Install one for postgreSQL from <a alt="https://odbc.postgresql.org/" href="https://odbc.postgresql.org/" title="https://odbc.postgresql.org/">their site</a> (use 64-bit version).
Working with Database
The database can be edited with any SQL client you prefer, or you can use our custom tool. It is a plugin for MS Excel, which simplifies editing tables by unpacking foreign keys. To use it, you need to install in from
Tools/ExcelDbAddin2, which installs it directly into MS Excel (it can be removed at any time in “Add or Remove programs”). It will appear as a new menu item called
Any changes made to the database will be visible in the Sandbox editor (with the exception of Localization). The game, however, reads the database from XML files inside Tables.pak or mod PAK files. To create such PAKs, use the editor’s <a alt="https://wiki.nexusmods.com/index.php/Modding_Tool" href="https://wiki.nexusmods.com/index.php/Modding_Tool" title="https://wiki.nexusmods.com/index.php/Modding_Tool">modding window</a> .
(Tip) Closing the Database
Don't fear the browser warning below, your setup is automatically saved and the browser can safely be closed without having to redo the database setup. You have to remember your password though.
<img alt="47833563-1584964929.png" src="" />
- Install PostgreSQL server.
- Install ODBC driver (64bit) for PostgreSQL.
- Open pgAdmin, it's installed with PostgreSQL package.
- Create ConfigDB database.
- Add uuid-ossp extension to that database.
- Edit Data_reference/sequences.sql number 10578 to <a alt="//forums.nexusmods.com/index.php?/topic/8510843-register-unique-modding-ids-20/" href="//forums.nexusmods.com/index.php?/topic/8510843-register-unique-modding-ids-20/" title="//forums.nexusmods.com/index.php?/topic/8510843-register-unique-modding-ids-20/">the ID you claimed</a>.
- Migrate files
psql.exe -f Data_reference/modding.sql -U postgres –d ConfigDB -q
psql.exe -f Data_reference/public.sql -U postgres –d ConfigDB -q
psql.exe -f Data_reference/sequences.sql -U postgres –d ConfigDB –q
- Configure your user.cfg in root directory
wh_sys_SQLServer = "127.0.0.1"
wh_sys_SQLDatabase = "ConfigDB"
wh_sys_SQLUser = "postgres"
wh_sys_SQLPassword = "YOUR DATABASE PASSWORD"
wh_sys_SQLBranch = "modding"
wh_sys_PreferredDB = SQL, TBL, XML
wh_sys_SQLWritable = 1
- Done, start editor.
Kingdom Come Deliverance Getting Started