开发者

Django sqlclear purpose

开发者 https://www.devze.com 2023-04-08 09:07 出处:网络
Can any one explain the use of sqlcl开发者_StackOverflow中文版ear ?.I have read the docsThe way you would use this type of command is when you are doing initial prototyping of an application.During th

Can any one explain the use of sqlcl开发者_StackOverflow中文版ear ?.I have read the docs


The way you would use this type of command is when you are doing initial prototyping of an application. During this phase, before any releases have been done, you're pretty free to iterate over the data model. manage.py gives you the ability to automatically create the data model from the python model with no additional steps, so the sqlclear command gives you the ability to generate (and run if you want) sql that resets the database to the state it was in before you installed the app.

As a developer, it's always nice to have a repeatable process to create a clean development environment. As another developer suggested, you can pipe the output of this directly into mysql:

python manage.py sqlclear <<YOURAPPNAME>> | mysql --user=<<YOURDBUSERNAME>> --password=<<YOURDBPASSWORD>> <<DBNAME>>

This is just one possible reason to use this command.


I suppose the idea is, along with the other sql.. commands, to be able to easily add, edit, delete, or recreate the tables that Django puts in by default when you do a syncdb. This could help with database migration, removing an app from a shared database, or whenever you need to do anything else to the database but can't just drop the entire database and start over.

Although I'm open to other points : ), This was always my impression.


I pipe the output from sqlclean to mysql to clean (or reset using sqlreset) the database

python manage.py <<appname>> sqlclean | mysql <<databasename>>

Regards, Raggi

0

精彩评论

暂无评论...
验证码 换一张
取 消