首页 > 编程语言 > 详细

python manage.py makemigrations & migrate

时间:2020-03-31 10:54:41      阅读:82      评论:0      收藏:0      [点我收藏+]

一、正常流程

 1.python manage.py makemigrations 

 或 python manage.py makemigrations  appname

2. Python manage.py migrate

   python manage.py migrate appname

 

 

二、由于某种原因,人工删除库表,migrations文件等。

1.delete  django_migrations, django_content_type ,admin_log, auth_group, auth_group_permission,auth_permission

2.python  manage.py makemigrations appname

3.python manage.py migrate --fake appname

--fake  (由于人工操作,migration与实际table不一致,--fale 不会执行sql操作,只是对migration做标记,生成django_migrations表的内容。 重新一致。)
对于有数据的表,想保留数据,并且migrations一致,很重要 Tells Django to mark the migrations as having been applied
or unapplied, but without actually running the SQL to change your database schema. This is intended for advanced users to manipulate the current migration state directly if they’re manually applying changes;
be warned that using --fake runs the risk of putting the migration state table into a state where manual recovery
will be needed to make migrations run correctl

 

三、其他系统的数据库,表和数据,想纳入django model框架管理,怎么办

参考:https://stackoverflow.com/questions/44470715/how-to-migrate-existing-table-using-django-and-python

python manage.py inspectdb

 

python manage.py makemigrations & migrate

原文:https://www.cnblogs.com/lxgbky/p/12603302.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!