---
title: "Quick Start"
description: "Create the configuration, then generate, run, roll back and list the migrations."
version: "6.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.

# Quick Start

What you need for a quick start:

* Configuration file in the root of your project (you can also pass them as parameters inside CLI environment)
* Create database table structure
* Execute command to generate migrations

After that, you can execute that migration (run) in another environment to create the same DB structure.

## Create the configuration file

The configuration file is a PHP file that returns an array. You can use any file name, for example `migrations.php`.

```php
<?php

return [
    'database'    => [
        'adapter'  => 'mysql',
        'host'     => '127.0.0.1',
        'port'     => 3306,
        'username' => 'root',
        'password' => '',
        'dbname'   => 'db-name',
    ],
    'application' => [
        'log-in-db'               => true,
        'migrations'              => 'db/migrations',
        // true - TIMESTAMP, false - versions
        'ts-based'                => true,
        'export-data-from-tables' => [
            // Tables names
        ],
    ],
];
```

:::warning[WARNING]
Since version 4.0.0, a PHP configuration file must return an array. If the file returns a different value, for example a `Phalcon\Config\Config` object, the package uses an empty configuration. The command then stops with the error `Cannot load database configuration`.
:::

For all the configuration keys, see [Configuration](/6.0/configuration).

## Generate migrations

**Basic generation**

```
vendor/bin/phalcon-migrations generate
```

**Generate a specific table and export data from it**

```
vendor/bin/phalcon-migrations generate \
    --config=migrations.php \
    --table=users \
    --data=oncreate
```

The `--table` option accepts:

* One table name: `--table=users`
* A comma-separated list of table names: `--table=users,roles`
* A table prefix with an asterisk: `--table=user*`

The package removes the spaces at the start and at the end of each name. For example, `--table="users, roles"` gives the tables `users` and `roles`. This also applies to `--export-data-from-tables` and `export-data-from-tables`.

For the data options, see [Export data](/6.0/migration-methods#export-data).

`generate` does not write a migration for the SQLite internal tables, for example `sqlite_sequence`, or for the PostgreSQL tables of an extension, for example `spatial_ref_sys` of PostGIS.

`generate` compares each table with the newest migration file of that table, in all the migrations directories. If no table changed, `generate` creates no version and shows this message:

```
Info: Nothing to generate: no table changed since the last version
```

The compare ignores the MySQL `AUTO_INCREMENT` value. If one table changed, `generate` writes the files of all the tables. With `--data` or `--export-data-from-tables`, `generate` always creates a version.

:::info[NOTE]
The format of the generated files changed in version 5.0.0. When the newest file of a table is an old file (see [Old migration files](/6.0/migration-files#old-migration-files)), the compare always finds a change. For this reason, the first `generate` after an update from 4.0.1 or earlier always creates a version, also when no table changed. That version has the new format, so the next `generate` compares with the new files.
:::

## Run migrations

```
vendor/bin/phalcon-migrations run
```

With `--table`, `run` migrates only the named tables of each version, but it adds the full version to the log. A later `run`, with or without `--table`, does not run the other tables of that version. It shows `Version 1.0.1 was already applied`. To run the other tables of the version, remove the version from the log, or roll back the version.

Use `--table` when one migrations directory has the migrations of more than one database, and each database uses its own tables and its own log.

If a version of the log has no version directory, for example a version of a different branch, `run` shows a warning for that version:

```
Warning: Version 1.0.5 is in the log, but it has no folder: run does not start from it
```

`run` then starts from the highest version of the log that has a version directory.

## Roll back migrations

To roll back, use `run` with `--version`. Set `--version` to a version that is earlier than the current version:

```
vendor/bin/phalcon-migrations run --version=1.0.1
```

The package goes back one version at a time. For each table, it calls the `down()` and `afterDown()` methods of the version that it removes. Then it calls the `morph()` method of the previous version. See [Migration methods](/6.0/migration-methods).

## List existing migrations

```
vendor/bin/phalcon-migrations list
```

The command shows each version and if it was applied:

```
┌───────────────────────────┬──────────────┐
│ Version                   │  Was applied │
├───────────────────────────┼──────────────┤
│ 1.0.0                     │            Y │
│ 1.0.1                     │            N │
└───────────────────────────┴──────────────┘
```

Source: https://migrations.phalcon.io/6.0/quick-start/index.mdx
