Sam Hooke

Run Django ` makemigrations` without a database

The makemigrations command does not require a database to be present. As such, it is actually quite straightforward to run makemigrations without even having a database. This can be very useful for the development cycle of: modifying model, run tests, update tests; without having to have a full deployment.

To run makemigrations when you don’t even have a, you can do the following. Assuming you are in the virtual environment with your Python package installed:

>>> from import execute_from_command_line
>>> execute_from_command_line(["", "makemigrations", "--settings=my_module.settings"])

This will then create the new migration inside your Python package within the site-packages folder in your virtual environment.

These are rough notes from whatever I was working on, interested in or thinking about at the time. They vary greatly in quality and length, but prove useful to me, and hopefully to you too!

← Previous: Avoid a process terminating when logging off a remote SSH session
Next: RabbitMQ handshake timeout caused by hostname change →