Django South:从另一个表迁移 FK
我正在做一些系统,我的表设计是这样的:
Table A:
- ID
- ForeignKey(C)
Table B:
- ID
- ForeignKey(A)
Table C:
- ID
由于一些需求的变化,我需要将ForeignKey(C)从A移动到B,所以它是这样的:
Table A:
- ID
Table B:
- ID
- ForeignKey(A)
- ForeignKey(C)
-Table C:
- ID
模式迁移很容易。但上次我在表 A 中已经有一些现有的 FK 数据。我不能立即删除它们。我需要将这个FK迁移到表B。B的结构不同,里面的数据也不同。当我将ForeignKey(C)添加到B的模型时,South要求我提供默认值,因为我没有提供任何默认值并且它不允许NULL。选择是退出 schemamigration 并手动添加默认值或提供 1 次值。
我的问题是,如何添加使用 South 从表 A 中的现有数据导入的默认/1 次值?我正在寻找这个类似的问题,但没有运气:(
谢谢。
I was doing some system and my table design was like this:
Table A:
- ID
- ForeignKey(C)
Table B:
- ID
- ForeignKey(A)
Table C:
- ID
Due to some requirement changes, I need to move ForeignKey(C) from A to B, so it goes like this:
Table A:
- ID
Table B:
- ID
- ForeignKey(A)
- ForeignKey(C)
-Table C:
- ID
The schema migration was easy. But last time I already have some existing FK data in table A. Which I can't just delete right away. I need to migrate this FK's to table B. The structure of B is different as well as it's data inside. When I add ForeignKey(C) to B's model, South was asking me for a default value because I didn't provide any default value and it is not allowing NULL. The choice was to quit schemamigration and add default value manually or provide 1-time value.
My question is, how can I add default/1-time value that is imported from existing data in table A using South?. I was searching for this similar problem but no luck :(
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在进行这种类型的迁移时,我总是创建 3 个迁移:
这样我就可以使用来自的自动模式迁移对于第一次和第三次向南迁移,只需要编写一些简单的转换代码即可。这与南方教程中的此示例类似。
When doing this type of migration I always create 3 migrations:
This way I can use the auto schemamigration from south for the first and the third migration and only have to write some simple conversion code. This works like this example in the south tutorial.