---
description: 'Learn what Migrations are in Medusa and how to run them. Migrations are used to make changes to the database schema that Medusa is linked to.'
---

import DocCardList from '@theme/DocCardList';
import Icons from '@theme/Icon';

# Migrations

In this document, you'll learn what Migrations are in Medusa.

## What are Migrations

Migrations are scripts that are used to make additions or changes to your database schema. In Medusa, they are essential for both when you first install your backend and for subsequent backend upgrades later on.

When you first create your Medusa backend, the database schema used must have all the tables necessary for the backend to run.

When a new Medusa version introduces changes to the database schema, you'll have to run migrations to apply them to your own database.

:::tip

Migrations are used to apply changes to the database schema. However, there are some version updates of Medusa that require updating the data in your database to fit the new schema. Those are specific to each version and you should check out the version under Upgrade Guides for details on the steps.

:::

---

## Migration Commands

### Migrate Command

Using the Medusa CLI tool, you can run migrations with the following command:

```bash
npx @medusajs/medusa-cli migrations run
```

This will check for any migrations that contain changes to your database schema that aren't applied yet and run them on your backend.

### Seed Command

Seeding is the process of filling your database with data that is either essential or for testing and demo purposes. In Medusa, the `seed` command will run the migrations to your database if necessary before it seeds your database with dummy data.

You can use the following command to seed your database:

```bash npm2yarn
npx @medusajs/medusa-cli@latest seed -f ./data/seed.json
```

This assumes that you have the file `data/seed.json` in your Medusa backend, which is available by default. It includes the demo data to seed into your database.

### Revert Migrations

To revert the last migration you ran, run the following command:

```bash
npx @medusajs/medusa-cli@latest migrations revert
```

### Other Migrations Commands

You can learn about migration commands available in the Medusa CLI tool by referring to the [Medusa CLI reference](../../../cli/reference.mdx#migrations)

---

## Custom Development

Developers can create custom entities in the Medusa backend, a plugin, or in a module, then ensure it reflects in the database using a migration.

<DocCardList colSize={6} items={[
  {
    type: 'link',
    href: '/development/entities/migrations/create',
    label: 'Create a Migration',
    customProps: {
      icon: Icons['academic-cap-solid'],
      description: 'Learn how to create migrations in Medusa.'
    }
  },
  {
    type: 'link',
    href: '/development/entities/create',
    label: 'Create an Endpoint',
    customProps: {
      icon: Icons['academic-cap-solid'],
      description: 'Learn how to create endpoints in Medusa.'
    }
  },
]} />