Using PostgreSQL with Django on a Mac

PostgreSQL on Mac via Brew

  • A quick and easy way of using PostgreSQL on Mac OS is to install it via Brew.
  • pgAdmin 4 provides a web interface for administering PostgreSQL and can be installed on a local developer machine.

    Django Migrations are Optional

    Django migrations are optional, and if you have difficulties with migrations there is a manual alternative, which can be preferable for some developers:

  • Create a schema.sql file which maintains all tables for your schema that you create (skip the tables automatically created by Django for user management).
  • Add schema.sql to your version control for the project.
  • Create tables manually, or with pgAdmin 4. With pgAdmin 4 you create right-click a table and generate the create table SQL script.
  • Turn off migrations for each model in Django:
class MyTable(models.Model):
    my_table_id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=256, blank=False)
    tag = models.CharField(max_length=256, blank=False)

    class Meta:
        managed = False
        db_table = 'account'
  • Disable migrations for each app that doesn’t use them in (as well as for the existing entries) in MIGRATION_MODULES, for example:
# Migration modules

    'my_app': None,

    'auth': None,
    'account': None,
    'contenttypes': None,
    'default': None,
    'sessions': None,

    'core': None,
    'profiles': None,
    'snippets': None,
    'scaffold_templates': None,

See also: Django Books

1 reply on “Using PostgreSQL with Django on a Mac”

In the same way as it’s a good idea to use virtualenv to keep your pip installed packages separate between different python projects, and pyenv so you can have projects using different python versions… it’s a good idea to run Postgres in docker, e.g. with docker-compose, so you can have different db config or versions between different projects.

Leave a Reply

Your email address will not be published. Required fields are marked *