Django post_save 和南迁移
我有一个针对所有对象(不仅仅是我的应用程序)的 post_save
信号,并在其中创建一个 SignalInfo
(该模型来自我的应用程序)对象,放置有关创建的信息/将对象编辑到其中并保存。在我开始使用南方迁移之前,它工作得很好。
问题是,当我现在执行 syncdb
时,不会创建我的应用程序的表(它们将在 ./manage.py migrate
之后),但会创建像 这样的新对象>auth.permission
正在 syncdb
期间创建,我的信号尝试创建 SignalInfo
对象,但它不能,因为我的应用程序的表尚未准备好,我有数据库错误。
我怎样才能让它发挥作用?
I have a post_save
signal for all objects (not only of my app) and in it I create a SignalInfo
(this model is from my app) object, put info about created/edited object into it and save it. It worked fine until I started using South migrations.
The problem is that when I do syncdb
now, tables for my app are not created (they will be after ./manage.py migrate
), but new objects like auth.permission
are being created during syncdb
and my signal tries to create SignalInfo
object but it can't because tables for my app are not ready and I have DatabaseError.
How can I make it work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将
SignalInfo
创建代码包装在try... except
块中,这样错误就不会干扰。唯一的副作用是syncdb
创建的初始模型不会有与之关联的SignalInfo
对象。You can wrap your
SignalInfo
creation code in atry...except
block so the error won't interfere. The only side-effect would be that the initial models created bysyncdb
won't haveSignalInfo
objects associated with them.