ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

python – Django South – 为已填充表格的应用程序创建初始迁移

2019-07-15 15:57:53  阅读:289  来源: 互联网

标签:python migration django django-south


场景:我的Django应用程序中有一个应用程序,我从未将其置于南方管理之下.很久以前我运行了一个syncdb,这个应用程序的模型从来没有改变过.在整个过程中,我显然已将数据添加到这些表中.

现在,我希望将此应用程序置于南方管理之下,但是一旦表格已经存在,我就可以创建迁移文件,但很自然地,我无法执行它们.我收到现有表的数据库错误:

django.db.utils.DatabaseError:(1050,“表’ooyala_ooyalaitem’已存在”)

这对我来说非常明显.我想知道的是,是否有一种智能方法来运行migrate命令来使用当前表.我不想转储数据,手动删除表,运行迁移和重新填充内容,也不想为此创建数据迁移.

有什么想法吗?它甚至可能吗?

谢谢你的时间.

解决方法:

This is covered in the manual.

Converting an app to use South is very easy:

  • Edit your settings.py and put ‘south’ into INSTALLED_APPS (assuming you’ve installed it to the right place)
  • Run ./manage.py syncdb to load the South table into the database. Note that syncdb looks different now – South modifies it.
  • Run ./manage.py convert_to_south myapp – South will automatically make and pretend to apply your first migration.

Note that you’ll need to convert before you make any changes; South detects changes by comparing against the frozen state of the last migration, so it cannot detect changes from before you converted to using South.

标签:python,migration,django,django-south
来源: https://codeday.me/bug/20190715/1469024.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有