加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

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

发布时间:2020-12-20 12:21:21 所属栏目:Python 来源:网络整理
导读:场景:我的Django应用程序中有一个应用程序,我从未将其置于南方管理之下.很久以前我运行了一个syncdb,这个应用程序的模型从来没有改变过.在整个过程中,我显然已将数据添加到这些表中. 现在,我希望将此应用程序置于南方管理之下,但是一旦表格已经存在,我就可
场景:我的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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读