I'm a novice trying to spin up my first webapp with a combination of Fly.io, Django, and a postgres DB but I'm having some trouble and can't find an answer in walkthroughs or Q&A.
I've set up a simple "Hello world" Django app (models.py is empty so far) and I'm trying to get all the components up and running before I build it out any further.
- I've successfully deployed my app on Fly.io with no errors
- I've created a postgres cluster on Fly.io using the instructions here: https://fly.io/docs/postgres/
- I've attached the cluster to my app, which generates a DB and sets an environment variable with the appropriate details (username, password, port, host, dbname)
- I've updated my settings.py file:
DATABASES = {} DATABASES["default"] = dj_database_url.config(conn_max_age=600, ssl_require=True)
- I've added to my fly.toml:
[[services]] internal_port = 5432 # Postgres instance protocol = "tcp" # Open port 10000 for plaintext connections. [[services.ports]] handlers = [] port = 10000
- I've confirmed I can get into the psql shell with
flyctl postgres connect -a MYAPP-pg
But unfortunately when I run python manage.py migrate
to check that everything is working, I get the following error:
File "<my_path>\venv\lib\site-packages\django\db\backends\base\base.py", line 282, in ensure_connection
self.connect()
File "<my_path>\venv\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "<my_path>\venv\lib\site-packages\django\db\backends\base\base.py", line 263, in connect
self.connection = self.get_new_connection(conn_params)
File "<my_path>\venv\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "<my_path>\venv\lib\site-packages\django\db\backends\postgresql\base.py", line 215, in get_new_connection
connection = Database.connect(**conn_params)
File "<my_path>\venv\lib\site-packages\psycopg2\__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not translate host name "top2.nearest.of.MYAPP-pg.internal" to address: Unknown host
Any ideas what might be happening? Any help would be very much appreciated!