How to configure Django to reinitialize and populate the entire database on startup?
Let's assume that you are working at the first version of a new Django application and you are keep adding changing the models.
Being a data-driven application you are mostly working to customize django admin.
In this case syncdb
is not too useful because it will fail to update models. South
was interesting but it does not make too much sense when you are working at the first version.
Deleting database and reinitializing it require several commands and also you manually entering the new admin account.
How do you propose to set your development environment so you can:
- auto-restart django server when files changed
- auto-reinitialize database when django is restarted
As a result, I expect to be able 开发者_Python百科to add a new attribute to a model, switch to the browser and refresh the admin page and see the new attribute.
Providing initial data for models
It’s sometimes useful to pre-populate your database with hard-coded data when you’re first setting up an app. There’s a couple of ways you can have Django automatically create this data: you can provide initial data via fixtures, or you can provide initial data as SQL.
In general, using a fixture is a cleaner method since it’s database-agnostic, but initial SQL is also quite a bit more flexible.
http://docs.djangoproject.com/en/dev/howto/initial-data/
精彩评论