开发者

How to configure Django to reinitialize and populate the entire database on startup?

开发者 https://www.devze.com 2023-02-17 15:42 出处:网络
Let\'s assume that you are working at the first version of a new Django application and you are keep adding changing the models.

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/

0

精彩评论

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

关注公众号