编程语言
首页 > 编程语言> > python – Django South – 为已填充表格的应用程序创建初始迁移

python – 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