更改 django 中的模型会导致数据库损坏?
我在 models.py 文件中添加和删除了字段,然后运行 manage.pysyncdb。通常我必须退出 shell 并重新启动它,然后才能使syncdb 执行任何操作。即使在那之后,我在尝试访问管理页面时遇到错误,似乎我添加的某些新字段仍然没有显示在模型中:
Caught an exception while rendering: no such column: mySite_book.Title
I have added and removed fields in my models.py file and then run manage.py syncdb. Usually I have to quit out of the shell and restart it before syncdb does anything. And then even after that, I am getting errors when trying to access the admin pages, it seems that certain new fields that I've added still don't show up in the model:
Caught an exception while rendering: no such column: mySite_book.Title
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Django 不会为您执行数据库迁移,即,如果您添加新字段,Django 不会修改您的数据库架构。
您可以:
Django does not perform database migration for you, i.e., if you add new fields, Django won't modify your database schema.
You can either:
对我来说,(只要您使用测试数据执行此操作,而不是在生产环境中执行此操作),只需删除 test.db 并执行新的 ./manage.pysyncdb 就容易得多。仅供思考...
For me, (so long as you're doing this with test data, and not doing this in a production environ) it's alot easier to just blow away the test.db and do a new ./manage.py syncdb. Just food for thought...
为了扩展@Barthelemy的答案,有几个 Django 迁移工具:
Just to expand on @Barthelemy's answer, there are several Django migration tools: