Skip to main content

tortoise-orm Tools.

Project description

Smart7_ORM

avatar

项目依赖

包名 版本
tortoise-orm ≥ 0.17.7
aerich ≥ 0.5.8

配置数据库

0x01 项目根目录配置settings.py

# mysql setting
database = {
    "db": 'MySQL',
    "host": "localhost",
    "username": "hubert",
    "password": "hubert",
    "db_name": "test_table",
}
# PostgreSQL setting
database = {
    "db": 'PostgreSQL',
    "host": "localhost",
    "username": "hubert",
    "password": "hubert",
    "db_name": "test_table",
}
# sqlite setting
database = {
    "db": 'SQLite',
    "db_name": "test_table.db",
}

0x02 自动获取模型所在包

from smart7_orm.utils import discover_models

model_list = discover_models()

0x03 数据库设置

from smart7_orm.core import make_sql
from smart7_orm.utils import discover_models

TORTOISE_ORM = {
    "connections": {"default": make_sql().get_url()},
    "apps": {
        "models": {
            "models": ["aerich.models", *discover_models()],
            "default_connection": "default",
        },
    },
}

迁移数据库

0x01 初始化迁移配置

aerich init

0x02 初始化数据库

aerich init-db

0x03 更新模型并进行迁移

aerich migrate

0x04 升级到最新版本

aerich upgrade

0x05 降级到指定版本

aerich downgrade

0x06 显示历史

aerich history

0x06 显示要迁移的头

aerich heads

更多请查看 aerich github

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smart7_orm-1.0.2.tar.gz (10.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page