<blockquote>
<p>Question part A. Does the database take precedence or do the project config files take precedence? When Craft loads and there is an inconsistency between both... which setting makes it to the admin screen, the one living in the DB or the one living in the YAML files?</p>
</blockquote>
<p>The database. In fact, Craft only uses the state in the database to display the interface. It only checks the YAML files to display the warnings if there's a discrepancy between the database state and the project config files. The YAML files are only used when you apply them manually, either using the <code>project-config/apply</code> command or through the backend under Utilities -&gt; Project Config.</p>
<blockquote>
<p>Question part B. When I do craft project-config/apply, does it sync files --&gt; database or database --&gt; files or both (considering the most recent change)?</p>
</blockquote>
<p>The former, it takes the YAML files in the config folder and applies those settings to the database. Though there are commands for both directions:</p>
<ul>
<li><code>project-config/apply</code> applies the YAML files in the <code>config/</code> folder to the database.</li>
<li><code>project-config/write</code> takes the config currently stored in the database and writes it out as YAML files in the <code>config/</code> folder. You usually don't need this since Craft does this automatically whenever you change something in the backend (unless you have <a href="https://craftcms.com/docs/3.x/project-config.html#manual-yaml-file-generation" rel="noreferrer">turned that off</a>).</li>
<li><code>project-config/rebuild</code> attempts to rebuild the entire project-config based on the state of the entire database. This is only required in rare edge-cases.</li>
</ul>
<p>All of this is explained in detail in the <a href="https://craftcms.com/docs/3.x/project-config.html" rel="noreferrer">documentation for the project config</a>.</p>

CC BY-SA 4.0
2022-03-01T13:09:24.700Z
Genius! ‍♂️
Álvaro Franz
CC BY-SA 4.0
2022-03-01T12:52:47.767Z
2022-03-01T12:52:47.767Z
MoritzLost
<p>I want to completely understand how Craft loads the current settings on a site.</p>
<p>And there are two things I didn't find in the documentation:</p>
<p><strong>Question part A</strong>. Does the database take precedence or do the project config files take precedence? When Craft loads and there is an inconsistency between both... which setting makes it to the admin screen, the one living in the DB or the one living in the YAML files?</p>
<p><strong>Question part B</strong>. When I do <code>craft project-config/apply</code>, does it sync <code>files --&gt; database</code> or <code>database --&gt; files</code> or both (considering the most recent change)?</p>

<config>
Project config priority between project config files and database
# Project config priority between project config files and database

(Asked by: username_0 on 2022-03-01)

I want to completely understand how Craft loads the current settings on a site.

And there are two things I didn't find in the documentation:

**Question part A**. Does the database take precedence or do the project config files take precedence? When Craft loads and there is an inconsistency between both... which setting makes it to the admin screen, the one living in the DB or the one living in the YAML files?

**Question part B**. When I do `craft project-config/apply`, does it sync `files --> database` or `database --> files` or both (considering the most recent change)?

**Tags:** config


---

## 1 answers

### Answer by username_1 on 2022-03-01. Score: 5 | Accepted answer

> Question part A. Does the database take precedence or do the project config files take precedence? When Craft loads and there is an inconsistency between both... which setting makes it to the admin screen, the one living in the DB or the one living in the YAML files?

The database. In fact, Craft only uses the state in the database to display the interface. It only checks the YAML files to display the warnings if there's a discrepancy between the database state and the project config files. The YAML files are only used when you apply them manually, either using the `project-config/apply` command or through the backend under Utilities -> Project Config.

> Question part B. When I do craft project-config/apply, does it sync files --> database or database --> files or both (considering the most recent change)?

The former, it takes the YAML files in the config folder and applies those settings to the database. Though there are commands for both directions:

* `project-config/apply` applies the YAML files in the `config/` folder to the database.
* `project-config/write` takes the config currently stored in the database and writes it out as YAML files in the `config/` folder. You usually don't need this since Craft does this automatically whenever you change something in the backend (unless you have [turned that off](https://craftcms.com/docs/3.x/project-config.html#manual-yaml-file-generation)).
* `project-config/rebuild` attempts to rebuild the entire project-config based on the state of the entire database. This is only required in rare edge-cases.

All of this is explained in detail in the [documentation for the project config](https://craftcms.com/docs/3.x/project-config.html).

> **Comments:**
> **username_0**: Genius! ‍♂️  

---

