django迁移文件丢失,修改模型类

1.不有的数据库数据

  1. 删除数据库所有的表
  2. 删除项目的migration模块中的所有 文件,除了__init__.py 文件
  3. 执行命令

1 python manage.py makemigrations 应用名
2 python manage.py migrate 应用名

2. 不删除现有的数据,生成 新的migration 文件,迁移模型类

  1. 先将应用模型类恢复到没有修改之前的状态
  2. 查看迁移情况
# 查看当前应用已经执行生效的迁移文件
python manage.py showmigrations 应用名

执行结果:
应用名
 [X] 0001_initial
 [x] 0002_add_model

     3. 重置应用迁移文件

    • 执行
复制代码
1 #
2 python manage.py migrate --fake 应用名 zero
3 
4 # 查看迁移
5 python manage.py showmigrations 应用名
6 
7 执行结果
8 [] 0001_initial
9 [] 0002_add_model
*前边的X没有了
复制代码
    • 删除app migrations下除init.py之外的所有文件
    • 删除数据库migrations表中该应用的所有迁移记录
    • 执行
python manage.py makemigrations 应用名

会再次生成0001_initial.py 之类的文件
    • 执行(这一步很关键)
1 python manage.py migrate 应用名 --fake-initial
2 
3 '''
4 --fake-inital 会在数据库migrations表中记录当前这个app 执行到 0001_initial.py ,但不会去执行迁移文件。
5 '''

     4. 修改应用模型类,并执行迁移命令

1 python manage.py makemigrations 应用名
2 python manage.py migrate 应用名

 

     

 

本文作者:一枚码农

本文链接:https://www.cnblogs.com/yimeimanong/p/15779872.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   一枚码农  阅读(469)  评论(0编辑  收藏  举报
 
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 Sold Out Hawk
  2. 2 光辉岁月 Beyond
Sold Out - Hawk
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

作词 : Jon Steingard

作曲 : Jon Steingard

I ain't like no one you met before

I'm running for the front

When they're all running for the door

And I won't sit down won't back out

You can't ever shut me up

Cause I'm on a mission

And I won't quit now

In a world full of followers

I'll be a leader

In a world full of doubters

I'll be a believer

I'm stepping out without a hesitation

Because the battle's already been won

I'm sold out

I'm no longer living

Just for myself

Running after Jesus

With my whole heart

And now I'm ready to show

I am sold out

I'm sold out

With every single

Step that I take now

With every drop of blood

Left in my veins

I'm gonna be making it count

I am sold out

This ain't just some temporary phase

You can't face this kind of grace

And leave the way you came

This is permanent with intent

And there won't be no stopping it now

I'm on a mission and it's heaven sent

In a world full of followers

I'll be a leader

In a world full of doubters

I'll be a believer

I'm stepping out without a hesitation

Cause my soul is like a stadium

I'm sold out

I'm no longer living

Just for myself

Running after Jesus

With my whole heart

And now I'm ready to shout

I am sold out

I'm sold out

With every single

Step that I take now

With every drop of blood

Left in my veins

I'm gonna be making it count

I am sold out

No trials coming against me

Could put a dent in my passion

They're just an opportunity

To put my faith into action

In a world full of followers

I'll be a leader

In a world full of doubters

I'll be a believer

I'm stepping out without a hesitation

I ain't got nothing left to be afraid of

I'm sold out

I'm no longer living

Just for myself

Running after Jesus

With my whole heart

And now I'm ready to show

I am sold out

I'm sold out

With every single

Step that I take now

With every drop of blood

Left in my veins

I'm gonna be making it count

I am sold out