I am using docker swarm to set env

```
- DATABASE_URL=postgres://basin:basin_pa44@postgres:5432/demo
```


I confirmed two host can reach each other. And directly using psycopg2 was 
fine:

```
>>> import psycopg2                                                        
                          
>>> conn = 
psycopg2.connect('postgres://basin:basin_pa44@postgres:5432/demo')          
              
>>> conn                                                                    
                         
<connection object at 0x7f8c71179b48; dsn: 'user=basin host=postgres 
password=xxx port=5432 dbname=d$
mo', closed: 0>                                                            
                          
>>> conn                                                                    
                         
KeyboardInterrupt                                                          
                          
>>> cur = conn.cursor()                                                    
                          
>>>                                                                        
                          
>>> cur.execute("""SELECT datname from pg_database""")                      
                         
>>> rows = cur.fetchall()                                                  
                          
>>> print "\nShow me the databases:\n"                                      
                         
                                                                            
                         
Show me the databases:                                                      
                         
                                                                            
                         
>>> for row in rows:                                                        
                         
...     print "   ", row[0]                                                
                          
...                                                                        
                          
    postgres                                                                
                         
    demo                                                                    
                         
    template1                                                              
                          
    template0                                                              
                          
```


django database settings : 
```
DATABASES = {
    'default': env.db(),
}
```

env:
```
>>> import environ                                                          
                         
>>> env = environ.Env()                                                    
                          
>>> env                                                                    
                          
<environ.environ.Env object at 0x7f8c6cf949d0>                              
                         
>>> env.db()                                                                
                         
{'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'demo', 
'HOST': 'postgres', 'USER': 'bas
in', 'PASSWORD': 'basin_pa44', 'PORT': 5432}                                
                         
```

error:

```
I am using docker swarm to set env
```
- DATABASE_URL=postgres://basin:basin_pa44@postgres:5432/demo
```

I confirmed two host can reach each other. And directly using psycopg2 was 
fine:
```
>>> import psycopg2                                                        
                          
>>> conn = 
psycopg2.connect('postgres://basin:basin_pa44@postgres:5432/demo')          
              
>>> conn                                                                    
                         
<connection object at 0x7f8c71179b48; dsn: 'user=basin host=postgres 
password=xxx port=5432 dbname=d$
mo', closed: 0>                                                            
                          
>>> conn                                                                    
                         
KeyboardInterrupt                                                          
                          
>>> cur = conn.cursor()                                                    
                          
>>>                                                                        
                          
>>> cur.execute("""SELECT datname from pg_database""")                      
                         
>>> rows = cur.fetchall()                                                  
                          
>>> print "\nShow me the databases:\n"                                      
                         
                                                                            
                         
Show me the databases:                                                      
                         
                                                                            
                         
>>> for row in rows:                                                        
                         
...     print "   ", row[0]                                                
                          
...                                                                        
                          
    postgres                                                                
                         
    demo                                                                    
                         
    template1                                                              
                          
    template0                                                              
                          
```

Database settings : 
```
DATABASES = {
    'default': env.db(),
}
```

env:
```
>>> import environ                                                          
                         
>>> env = environ.Env()                                                    
                          
>>> env                                                                    
                          
<environ.environ.Env object at 0x7f8c6cf949d0>                              
                         
>>> env.db()                                                                
                         
{'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'demo', 
'HOST': 'postgres', 'USER': 'bas
in', 'PASSWORD': 'basin_pa44', 'PORT': 5432}                                
                         
```

error:

```
I am using docker swarm to set env
```
- DATABASE_URL=postgres://basin:basin_pa44@postgres:5432/demo
```

I confirmed two host can reach each other. And directly using psycopg2 was 
fine:
```
>>> import psycopg2                                                        
                          
>>> conn = 
psycopg2.connect('postgres://basin:basin_pa44@postgres:5432/demo')          
              
>>> conn                                                                    
                         
<connection object at 0x7f8c71179b48; dsn: 'user=basin host=postgres 
password=xxx port=5432 dbname=d$
mo', closed: 0>                                                            
                          
>>> conn                                                                    
                         
KeyboardInterrupt                                                          
                          
>>> cur = conn.cursor()                                                    
                          
>>>                                                                        
                          
>>> cur.execute("""SELECT datname from pg_database""")                      
                         
>>> rows = cur.fetchall()                                                  
                          
>>> print "\nShow me the databases:\n"                                      
                         
                                                                            
                         
Show me the databases:                                                      
                         
                                                                            
                         
>>> for row in rows:                                                        
                         
...     print "   ", row[0]                                                
                          
...                                                                        
                          
    postgres                                                                
                         
    demo                                                                    
                         
    template1                                                              
                          
    template0                                                              
                          
```

Database settings : 
```
DATABASES = {
    'default': env.db(),
}
```

env:
```
>>> import environ                                                          
                         
>>> env = environ.Env()                                                    
                          
>>> env                                                                    
                          
<environ.environ.Env object at 0x7f8c6cf949d0>                              
                         
>>> env.db()                                                                
                         
{'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'demo', 
'HOST': 'postgres', 'USER': 'bas
in', 'PASSWORD': 'basin_pa44', 'PORT': 5432}                                
                         
```

error:

```
I am using docker swarm to set env
```
- DATABASE_URL=postgres://basin:basin_pa44@postgres:5432/demo
```

I confirmed two host can reach each other. And directly using psycopg2 was 
fine:
```
>>> import psycopg2                                                        
                          
>>> conn = 
psycopg2.connect('postgres://basin:basin_pa44@postgres:5432/demo')          
              
>>> conn                                                                    
                         
<connection object at 0x7f8c71179b48; dsn: 'user=basin host=postgres 
password=xxx port=5432 dbname=d$
mo', closed: 0>                                                            
                          
>>> conn                                                                    
                         
KeyboardInterrupt                                                          
                          
>>> cur = conn.cursor()                                                    
                          
>>>                                                                        
                          
>>> cur.execute("""SELECT datname from pg_database""")                      
                         
>>> rows = cur.fetchall()                                                  
                          
>>> print "\nShow me the databases:\n"                                      
                         
                                                                            
                         
Show me the databases:                                                      
                         
                                                                            
                         
>>> for row in rows:                                                        
                         
...     print "   ", row[0]                                                
                          
...                                                                        
                          
    postgres                                                                
                         
    demo                                                                    
                         
    template1                                                              
                          
    template0                                                              
                          
```

Database settings : 
```
DATABASES = {
    'default': env.db(),
}
```

env:
```
>>> import environ                                                          
                         
>>> env = environ.Env()                                                    
                          
>>> env                                                                    
                          
<environ.environ.Env object at 0x7f8c6cf949d0>                              
                         
>>> env.db()                                                                
                         
{'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'demo', 
'HOST': 'postgres', 'USER': 'bas
in', 'PASSWORD': 'basin_pa44', 'PORT': 5432}                                
                         
```

error:

```
bidspy_demo.1.8wqwj0o2s...@nd4.csp.ali    | You have 22 unapplied 
migration(s). Your project may not work properly until you apply the 
migrations for app(s): admin, 
uth, authtools, contenttypes, easy_thumbnails, orders, profiles, sessions.
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |   File 
"/usr/lib/python2.7/site-packages/django/utils/autoreload.py", line 227, in 
wrapper
bidspy_demo.1.8wqwj0o2s...@nd4.csp.ali    | Run 'python manage.py migrate' 
to apply them.
bidspy_demo.1.8wqwj0o2s...@nd4.csp.ali    | February 24, 2018 - 01:42:11
bidspy_demo.1.8wqwj0o2s...@nd4.csp.ali    | Django version 1.11.3, using 
settings 'demo.settings.development'
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |     fn(*args, **kwargs)
bidspy_demo.1.8wqwj0o2s...@nd4.csp.ali    | Starting development server at 
http://0.0.0.0:8000/
bidspy_demo.1.8wqwj0o2s...@nd4.csp.ali    | Quit the server with CONTROL-C.
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |   File 
"/usr/lib/python2.7/site-packages/django/core/management/commands/runserver.py",
 
line 128, in inner_run
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |     self.check_migrations()
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |   File 
"/usr/lib/python2.7/site-packages/django/core/management/base.py", line 
422, in check_migrations
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |     executor = 
MigrationExecutor(connections[DEFAULT_DB_ALIAS])
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |   File 
"/usr/lib/python2.7/site-packages/django/db/migrations/executor.py", line 
20, in __init__
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |     self.loader = 
MigrationLoader(self.connection)
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |   File 
"/usr/lib/python2.7/site-packages/django/db/migrations/loader.py", line 52, 
in __init__
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |     self.build_graph()
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |   File 
"/usr/lib/python2.7/site-packages/django/db/migrations/loader.py", line 
209, in build_graph
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |     self.applied_migrations = 
recorder.applied_migrations()
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |   File 
"/usr/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 
65, in applied_migrations
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |     self.ensure_schema()
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |   File 
"/usr/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 
52, in ensure_schema
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |     if 
self.Migration._meta.db_table in 
self.connection.introspection.table_names(self.connection.cursor()):
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |   File 
"/usr/lib/python2.7/site-packages/django/db/backends/base/base.py", line 
254, in cursor
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |     return self._cursor()
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |   File 
"/usr/lib/python2.7/site-packages/django/db/backends/base/base.py", line 
229, in _cursor
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |     self.ensure_connection()
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |   File 
"/usr/lib/python2.7/site-packages/django/db/backends/base/base.py", line 
213, in ensure_connection
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |     self.connect()
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |   File 
"/usr/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |     six.reraise(dj_exc_type, 
dj_exc_value, traceback)
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |   File 
"/usr/lib/python2.7/site-packages/django/db/backends/base/base.py", line 
213, in ensure_connection
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |     self.connect()
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |   File 
"/usr/lib/python2.7/site-packages/django/db/backends/base/base.py", line 
189, in connect
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |     self.connection = 
self.get_new_connection(conn_params)
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |   File 
"/usr/lib/python2.7/site-packages/django/db/backends/postgresql/base.py", 
line 176, in get_new_connection
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |     connection = 
Database.connect(**conn_params)
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |   File 
"/usr/lib/python2.7/site-packages/psycopg2/__init__.py", line 130, in 
connect
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |     conn = _connect(dsn, 
connection_factory=connection_factory, **kwasync)
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    | 
django.db.utils.OperationalError: could not translate host name "postgres" 
to address: Name does not resolve
bidspy_demo.1.hwvttaki2...@nd2.csp.ali    |
```

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3ebf18f8-e910-444e-9572-99a4c25c720d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to