---
title: "Migrations Log"
description: "How the package records the versions that it applies: the file log and the database log."
version: "4.0"
---

> Documentation Index
> Fetch the complete documentation index at: https://migrations.phalcon.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Migrations Log

The package records each version that it applies. It uses the log to find the versions to run, and to show the status in `list`.

* **File**. The log is the `.phalcon/migration-version` file in the project directory. To use a different file, set `log-path` or `--log-path`. If the directory of the file does not exist, the package creates it.
* **Database**. Set `log-in-db` to `true`, or use the `--log-in-db` option. The log is the `phalcon_migrations` table. To use a different table, set `log-table` or `--log-table`. If the table does not exist, the package creates it. The table has the columns `version`, `start_time` and `end_time`. When `generate` runs for all the tables, it skips the log table.

:::warning[WARNING]
The file log and the database log are separate. Use the same log setting for all the `run`, `list` and `clean` commands of a project.
:::

## The default log

In version 4, the file log is the default. In version 5.0, the database log becomes the default.

If no setting chooses the log, `run`, `list` and `clean` give this PHP deprecation notice:

```
The file log is the default in 4.x. 5.0 uses the database log. Set log-in-db (migrationsInDb in PHP) to true, then run import-log, or set it to false to keep the file log.
```

To stop the notice, choose the log with one of these settings:

* `log-in-db` in the configuration, `true` or `false`
* `--log-in-db` or `--log-in-db=false` on the CLI
* The `migrationsInDb` key in a call to `Migrations::run()`, `Migrations::listAll()` or `Migrations::clean()`

## Move the file log to the database

The `import-log` action copies the versions of the file log into the log table of the database. It does this one time, for a new log table.

To move a project to the database log:

1. Set `log-in-db` to `true` in the configuration.
2. Run `import-log` for each database that the file log describes:

    ```
    vendor/bin/phalcon-migrations import-log --config=migrations.php
    ```

3. Run `list` and make sure that the versions are applied.
4. Delete the file log.

`import-log` uses the database of the configuration, and the file log and the log table of your settings (`log-path` and `log-table`, or the defaults). It puts all the versions in one transaction. The `start_time` and `end_time` values are the time of the import. The file log does not change.

`import-log` stops with an error, and changes nothing, in these conditions:

* The log table has a line.
* The database has no table other than the log table. The file log cannot describe an empty database.
* The file log does not exist, or has no version.

When you use the database log, `run` stops before it changes the database if all these conditions are true:

* The log table is empty.
* The file log has versions.
* The database has a table other than the log table.

The error is:

```
The log table '<table>' is empty, but the file log '<file>' has <N> versions. If the file is the log of this log table, run import-log. If not, delete or rename the file.
```

This stops `run` from applying all the versions again on a database that already has the tables. On an empty database, `run` applies all the versions as usual. The empty database can be a new database, or a database after `clean --force`.

`Migrations::importLog()` does the same in PHP. It accepts the `config`, `directory`, `log-path` and `log-table` keys.

## Many databases

To keep the migrations of more than one database, use one configuration file for each database.

* With the file log, give each configuration its own `log-path`.
* With the database log, each database has its own log table.
* For two sets of migrations in one database, give each set its own `log-table`.

```
vendor/bin/phalcon-migrations run --config=config/main.php
vendor/bin/phalcon-migrations run --config=config/reports.php
```

:::warning[WARNING]
When the log table of a set of migrations is empty, `run` reads the file log at the `log-path` of that set. If a different set keeps its file log in the same project directory, give the first set a `--log-path` of its own. If you do not, `run` can stop with the error of the empty log table.
:::

Source: https://migrations.phalcon.io/4.0/log/index.mdx
