Hello, I have a project running on django and postgres. When I run it on fly it works as I created a superuser and I can login to the admin page. However when I try running it locally or do a migration I get this error “django.db.utils.OperationalError: could not translate host name “neighbornook-database.flycast” to address: nodename nor servname provided, or not known”.
This is how I implemented the Database into my settings.py DATABASE_URL=os.getenv(“DATABASE_URL”)
if DATABASE_URL:
DATABASES = {
‘default’: dj_database_url.parse(DATABASE_URL),
}
else:
DATABASES = {
‘default’: {
‘ENGINE’: ‘django.db.backends.sqlite3’,
‘NAME’: BASE_DIR / ‘db.sqlite3’,
}
}
And this is how I have my DATABASE_URL in my .env file: DATABASE_URL=postgres://neinook_bd:HiJVm@neighbornook-database.flycast:5432/nek_backend
.flycast is private (internal in fly’s infra), ie it’s not accessible outside of the org’s fly machines… ie it won’t work locally b/c your machine has no idea what .flycast is.
Hello, thank you for your response. I am new to programming I’m learning now and also this is my first time using fly. I looked into the documentation that you provided but I do not understand completely how to resolve the issue. I want to ask if I remove the fly database from my settings.py will it still work when I make changes locally and deploy it? Meaning all the modules and information I put locally will it connect to the fly database when I deploy it?
You need to set this to use .fly.dev in the environment where you’re deploying (local machine or in CI/CD). You’ll still want to use .flycast in your app’s environment though, that way it’ll communicate internally in the app instance rather than making an external network call to itself.
Also, I hope you didn’t leak your DB name/password in your first post, you should rotate the creds if those are the real creds.