Django: flush command doesnt completely clear database, reset fails

﹥>﹥吖頭↗ 提交于 2019-12-04 03:51:24

I thought that flush was supposed to drop all tables.

No. According to the documentation, manage.py flush doesn't drop the tables. Instead it does the following:

Returns the database to the state it was in immediately after syncdb was executed. This means that all data will be removed from the database, any post-synchronization handlers will be re-executed, and the initial_data fixture will be re-installed.

As stated in chapter 10 of The Django Book in the "Making Changes to a Database Schema" section,

syncdb merely creates tables that don't yet exist in your database — it does not sync changes in models or perform deletions of models. If you add or change a model's field, or if you delete a model, you’ll need to make the change in your database manually.

Therefore, to solve your problem you will need to either:

  1. Delete the database and reissue manage.py syncdb. This is the process that I use when I'm still developing the database schema. I use an initial_data fixture to install some test data, which also needs to be updated when the database schema changes.
  2. Manually issue the SQL commands to modify your database schema.
  3. Use South.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!