Django South正在为已经填充表的应用程序创建初始迁移

2024-05-01 08:03:25 发布

您现在位置:Python中文网/ 问答频道 /正文

场景:我的Django应用程序中有一个应用程序,我从未将其置于South管理之下。很久以前我运行过一个syncdb,这个应用程序的模型从未改变过。一直以来,我都在这些表中添加了数据。在

现在,我希望将这个应用程序置于south管理之下,但是一旦表已经存在,我就可以创建迁移文件,但是很自然,我不能执行它们。我收到现有表的数据库错误:

django.db.utils.DatabaseError: (1050, "Table 'ooyala_ooyalaitem' already exists")

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

有什么想法吗?有可能吗?在

谢谢你的时间。在


Tags: 文件数据django模型数据库应用程序db错误
1条回答
网友
1楼 · 发布于 2024-05-01 08:03:25

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.

相关问题 更多 >