开发者

Database choice choice for Django project

开发者 https://www.devze.com 2023-02-06 19:54 出处:网络
Django (http://djangoproject.com) framework currently supports the following databases: PostgreSQL, SQLite 3, MySQL 5 and Oracle. This question is not about the comparison of these databases, contrari

Django (http://djangoproject.com) framework currently supports the following databases: PostgreSQL, SQLite 3, MySQL 5 and Oracle. This question is not about the comparison of these databases, contrariwise I want to know details about their 开发者_StackOverflowcompatibility with Django and how one should choose an adequate database for a simple (but growing) project.


It depends. If you don't want to pay the (huge) premium for Oracle, your choice is between MySQL and PostgreSQL (SQLite is mostly meant for development, not production). PostgreSQL seems to be the choice of most Django core devs (Andrew Godwin went as far as putting "friends don't let friends use MySQL" into a DjangoCon talk). Nevertheless, MySQL is fully supported by Django and is used by many Django websites in production.

IMHO, PostgreSQL has two clear advantages over MySQL:

  • If you use GeoDjango. There's really no alternative to PostGIS. MySQL's GIS support is lackluster at best.
  • South. MySQL is not able to use transactions during schema migrations, which means if a South migration goes awry, you're hanging between two migrations without clear way forward or backward. PostgreSQL saves a lot of pain in such situations.


The quick answer is it doesn't really matter but if I had to pick one, it would probably be PostgreSQL.

The original Django developers heavily recommended PostgreSQL in the early days. PostgreSQL is arguably/technically a 'better' database then MySQL so if you've never used it before it might be worth investing some time to lean it.

Now-a-days though I'd say it's safe to assume that all the DB drivers work equally well. So if you are more familiar with MySQL or Oracle there should be no problems using them instead. I've only used Django with MySQL and haven't had any problems.


All of the pluggable databases are supported, meaning, the the model/db-layer will abstract the db-specifics for you. As for performance, I'd suggest MySQL 5 or Postgresql. Oracle will definitely perform well, but might be more expensive in the long run. If you are just started your project, sqlite3 is your friend, simply because the it will be setup within seconds.

Handling parallel settings for development and production has been discussed in various blog posts, e.g. in this one:

  • http://ericholscher.com/blog/2011/jan/10/handling-django-settings-files/
0

精彩评论

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