django 做 migrate 时 表已存在的处理方法
作者:xufwind 时间:2022-02-14 16:11:53
在开发web的时候,如果是以前已存在的项目,项目下载下来后,为了使用测试库的数据,会直接将整个测试库(如sqlite3)拿到本机来。这种情况下,如果执行的顺序不对,很容易在执行migrate的时候出现数据库已存在的错误:
django.db.utils.OperationalError: (1050, "Table 'xxx' already exists")
要处理这种情况,如果是数据表都已经存在了,在migrate时直接使用 --fake-initial 来处理
python manage.py migrate --fake-initial
如果是因有外键存在,需要初始化多个表,且有部分数据表已创建,又有部分未创建,可以使用 --fake <appname>来处理
python manage.py migrate --fake <appname>
参考:https://stackoverflow.com/questions/25924858/django-1-7-migrate-gets-error-table-already-exists
来源:https://blog.csdn.net/xufwind/article/details/85774199
标签:django,migrate,表
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
基于Python3制作一个带GUI界面的小说爬虫工具
2023-04-02 17:33:04
![](https://img.aspxhome.com/file/2023/5/84125_0s.png)
python使用Qt界面以及逻辑实现方法
2023-10-23 23:28:09
![](https://img.aspxhome.com/file/2023/4/87644_0s.png)
python绘制地震散点图
2021-12-21 13:09:08
![](https://img.aspxhome.com/file/2023/5/82545_0s.jpg)
Python如何优雅删除字符列表空字符及None元素
2023-10-26 19:17:00
[多图]新:60个国外创意404页面设计
2008-12-05 12:00:00
![](https://img.aspxhome.com/file/UploadPic/up/9-404.gif)
Python 使用SFTP和FTP实现对服务器的文件下载功能
2023-10-29 09:39:40
PHP开发实现快递查询功能详解
2023-11-24 12:19:39
![](https://img.aspxhome.com/file/2023/3/55723_0s.png)
推荐技术人员一款Python开源库(造数据神器)
2023-11-10 19:57:45
![](https://img.aspxhome.com/file/2023/6/93716_0s.jpg)
微信小程序实现登陆注册滑块验证
2023-08-24 17:36:26
![](https://img.aspxhome.com/file/2023/7/56127_0s.jpg)
Python-GUI wxPython之自动化数据生成器的项目实战
2021-06-08 14:43:18
![](https://img.aspxhome.com/file/2023/2/93802_0s.png)
对pandas的算术运算和数据对齐实例详解
2023-05-29 07:24:51
python网络爬虫精解之正则表达式的使用说明
2023-02-26 17:13:21
![](https://img.aspxhome.com/file/2023/7/104997_0s.png)
JAVA/JSP学习系列之一
2023-06-19 16:44:14
python实时监控logstash日志代码
2021-03-08 07:46:49
PyTorch搭建多项式回归模型(三)
2022-09-04 00:43:49
![](https://img.aspxhome.com/file/2023/3/124813_0s.gif)
把vgg-face.mat权重迁移到pytorch模型示例
2021-11-03 16:29:20
python冒泡排序简单实现方法
2022-09-27 12:28:57
ORACLE常用数值函数、转换函数、字符串函数
2023-07-21 02:03:40
python函数和python匿名函数lambda详解
2021-08-22 17:57:07
Pycharm安装scrapy及初始化爬虫项目的完整步骤
2023-04-03 10:49:43
![](https://img.aspxhome.com/file/2023/4/108114_0s.jpg)