首页 > 科技热点 > 正文内容

django数据库迁移命令

时间:2024-10-03 01:01:23

django 数据迁移命令详解

# 01 清空django_migrations所有记录 delete FROM public . django_migrations # 02 清空工程目录下的所有迁移文件 find . - path "*/migrations/*.py" - not - name "__init__.py" - delete find . - path "*/migrations/*.pyc" - delete * * * * * * 如果,你确定数据库与app的models . py同步,则不需要第 03 与 04 步骤 * * * * * # 03 导出数据库表结构为模型文件 python manage . py inspectdb > . / db_models . py # 04 核查每个app的模型文件与db_models.py中有无差异?有差异需要依据数据库修改app下的models.py文件 - 这里需要备份每个app的models . py , 人工check与修改models . py保持与数据库同步。

1. migrate参数说明。位置参数 : app_label 指定同步的应用程序标签 . migration_name Database state will be brought to the state after that migration . Use the name "zero" to unapply all migrations . 可选参数 : - h , -- help show this help message and exit -- noinput , -- no - input 告诉Django不要提示用户输入任何类型的信息。 . -- database DATABASE 指定要同步的数据库。默认为“ default ”数据库 . -- fake 将迁移标记为运行而不实际运行它们 . -- fake - initial 检测表是否已经存在,假若已经应用了初始迁移。

2. makemigrations参数说明。位置参数 : app_label 指定要为其创建迁移的应用程序标签 . 可选参数 : -- dry - run 只需显示将要进行的迁移;不要实际编写它们。 -- merge 启用迁移冲突的修复。 -- empty 创建空迁移 . -- noinput , -- no - input 告诉Django不要提示用户输入任何类型的信息 . - n NAME , -- name 名称,将此名称用于迁移文件 . -- no - header 不要向新迁移文件添加头注释。 -- check 如果模型更改丢失迁移,则以非零状态退出 . -- version show program ' s version number and exit - v { 0 , 1 , 2 , 3 } , -- verbosity { 0 , 1 , 2 , 3 } Verbosity level ; 0 = minimal output , 1 = normal output , 2 = verbose output , 3 = very verbose output -- settings SETTINGS The Python path to a settings module , e . g . "myproject.settings.main" . If this isn ' t provided , the DJANGO_SETTINGS_MODULE environment variable will be used . -- pythonpath PYTHONPATH A directory to add to the Python path , e . g . "/home/djangoprojects/myproject" . -- traceback Raise on CommandError exceptions -- no - color Don ' t colorize the command output . -- force - color Force colorization of the command output .

版权声明:转载此文是出于传递更多信息之目的。若有来源标注错误或侵犯了您的合法权益, 请作者持权属证明与本网联系,我们将及时更正、删除,谢谢您的支持与理解。
标签:科技热点

科技之家 广州小漏斗信息技术有限公司 版权所有 提供支持 粤ICP备20006251号