Aerich

0.9.2 · active · verified Thu Apr 16

Aerich is a database migrations tool specifically designed for Tortoise ORM. It automates schema evolution by generating and applying migration scripts, making it easier to manage database changes in Python projects. It is actively maintained, with version 0.9.2 being the latest as of early 2024, and features regular releases for bug fixes and new functionality.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart provides the content for a `config.py` file, defining a simple Tortoise-ORM configuration (`TORTOISE_CONFIG`) and a `User` model. To use Aerich: 1. Save the above content as `config.py` in your project root. 2. Run the following commands in your terminal to initialize Aerich, create, and apply migrations: ```bash aerich init -t config.TORTOISE_CONFIG aerich migrate aerich upgrade ```

# config.py
from tortoise import fields, models

class User(models.Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=255)

    class Meta:
        table = "users"


TORTOISE_CONFIG = {
    "connections": {"default": "sqlite://db.sqlite3"},
    "apps": {
        "models": {
            "models": ["config", "aerich.models"], # "config" refers to models defined in this file
            "default_connection": "default",
        }
    },
}

view raw JSON →