首次部署时的 Django syncdb

Django syncdb on first deployment

所以我已经成功地使用 django 1.8 创建了一个站点并且我准备好部署了。我有几个新模型,我正在使用具有自己模型的 django-allauth。我还设法使用配置文件更改设置以使用不同的数据库进行生产和开发,以及在生产时关闭调试等。

我已将我的项目文件夹上传到生产服务器,并准备在 http.conf 中为 Apache 添加新行,但我无法全神贯注于数据库。 我是否在生产服务器上 运行 syncdb 或 makemigrations? django 如何知道使用生产数据库而不是开发数据库。我的设置从套接字中查找主机名来决定它是生产还是开发。

接下来我该做什么?

来自docs

You should think of migrations as a version control system for your database schema. makemigrations is responsible for packaging up your model changes into individual migration files - analogous to commits - and migrate is responsible for applying those to your database.

The migration files for each app live in a “migrations” directory inside of that app, and are designed to be committed to, and distributed as part of, its codebase. You should be making them once on your development machine and then running the same migrations on your colleagues’ machines, your staging machines, and eventually your production machines.

因此,您在开发机器上进行迁移,然后 运行 在任何其他机器上进行迁移。

syncdb 自 django 1.7

以来已更改为 migrate

Migrations New in Django 1.7.

Migrations are Django’s way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema. They’re designed to be mostly automatic, but you’ll need to know when to make migrations, when to run them, and the common problems you might run into.

Prior to version 1.7, Django only supported adding new models to the database; it was not possible to alter or remove existing models via the syncdb command (the predecessor to migrate).

migratemakemigrations 之间的区别由 doru 很好地说明。