---
title: "Other Actions"
description: "Clean the database and export the schema."
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.

# Other Actions

## Clean the database

The `clean` action drops the tables of the database, or deletes their data. It does not drop the log table, the SQLite internal tables (for example `sqlite_sequence`) or the PostgreSQL tables of an extension. Without `--force`, it stops with the error `The clean action drops tables or deletes data: add --force to run it.`

```
vendor/bin/phalcon-migrations clean --force
```

| Command                             | Result                                                                                 |
|-------------------------------------|----------------------------------------------------------------------------------------|
| `clean --force`                     | Drops all the tables and empties the log. The next `run` starts from the first version |
| `clean --force --table=users,roles` | Drops only these tables. The log does not change                                       |
| `clean --force --data-only`         | Deletes the rows of all the tables, and keeps the tables. The log does not change      |

`--table` accepts table names, separated with commas. Tables that refer to each other work.

## Export the schema

The `export` action shows the SQL of the schema of the migration files at a version. The default is the newest version.

```
vendor/bin/phalcon-migrations export --config=migrations.php --version=1.0.0
```

The output has the `CREATE TABLE` statements first. Then it has the other statements of the tables, for example the PostgreSQL and SQLite indexes and the PostgreSQL column comments. Then it has the foreign keys. For the example file above, the output on MySQL is:

```sql
CREATE TABLE `users` (
    `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
    `email` VARCHAR(255) NOT NULL COMMENT 'Login email',
    `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    UNIQUE KEY `users_email_uindex` (`email`)
) ENGINE=InnoDB COLLATE=utf8mb4_unicode_ci;
```

* To export only some tables, use `--table` with table names, separated with commas.
* For each table, `export` uses the newest file of the table that is not after the version, in all the migrations directories.
* The names have no schema.
* The output has no data.
* The database does not change. If a `morph()` method has code other than `morphTable()`, `export` runs that code.

To write the SQL to a file, redirect the output. The banner and the error messages go to stderr, so the file has only the SQL:

```
vendor/bin/phalcon-migrations export --config=migrations.php > schema.sql
```

:::info[NOTE]
When `display_errors` is on, PHP shows its notices on stdout, for example the deprecation notices of the old configuration keys. The notices are then in the file. Use the new names of the keys, or send the PHP notices to stderr:

```
php -d display_errors=stderr vendor/bin/phalcon-migrations export --config=migrations.php > schema.sql
```
:::

Source: https://migrations.phalcon.io/6.0/other-actions/index.mdx
