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

# 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](/4.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*`

For the data options, see [Export data](/4.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 version and 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 after version 4.0.1. For this reason, the first `generate` after an update from 4.0.1 or earlier always creates a version.
:::

## Run migrations

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

## 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](/4.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/4.0/quick-start/index.mdx
