Skip to content

Exception Target: Loading the database

Moritz Ringler edited this page Jun 21, 2021 · 1 revision

To support preloading in PHP 7.4, it was necessary to change the process how database tables are loaded into Propel.

After an update to the latest version, this might lead to an exception:

Fatal error: Uncaught Propel\Runtime\Exception\PropelException: Your configuration is outdated. Please rebuild it with the config:convert command.

Fixing this is easy, the necessary steps depend on whether the configuration is directly imported into the project (i.e. via require_once('path/to/conf.php')), or set manually by registering a ConnectionManager (i.e. Propel::getServiceContainer()->setConnectionManager('my-connection', $manager)).

For imported configuration

In most cases, the configuration file is generated with the config:convert command from a source file (i.e. propel.yaml, propel.json, propel.ini, ...). The created PHP file (i.e. conf.php) is then imported into the project with a require_once statement.

In this case, fixing an outdated configuration should be as easy as running the config:convert command again:

./vendor/bin/propel config:convert --config-dir path/to/your/config/folder

This will update the configuration version, and add a statement at the end of the file, which imports the loading script.

Note that the model:build command has to be run at least once after the update, in order for the script to be available. If you want the script at a different location, you can pass the --loader-script-dir parameter to both model:build and config:convert, or set the parameter paths.loaderScriptDir in the configurarion.

For manually built configuration

If the configuration is built manually, the loader script has to be imported manually as well through a require_once. The script is called loadDatabase.php, and will be created when running the model:build command. The default location is at ./generated-conf, but this can be changed by passing the --loader-script-dir parameter to model:build. A good place to import the script is after the configuration has been set:

require_once('path/to/loadDatabase.php');

The error about an outdated configuration is triggered by a call to StandardServiceContainer->checkVersion('dev-master'). The current correct version is 2, so in order to be made aware of future changes, the call needs to be adjusted:

StandardServiceContainer->checkVersion(2);

Fixing uninitialized database error

If the database is not imported, Propel fails with an exception:

Fatal error: Uncaught Propel\Runtime\Exception\PropelException: Database map was not initialized. Please check the database loader script included by your conf

This means that the script was never created by config:convert, or that it was created at a different location, most likely by passing different values for --loader-script-dir to model:build and config:convert. Make sure that model:build was executed, and that the correct file is imported by your configuration.

If you are setting the configuration manually, please make sure you import the correct file, as described in the section above.