I tried to group serveral apps into a "app" folder for better management. however i got the below error when i did the first migration.
./manage.py makemigrations
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/core/management/__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 132, in handle
migration_name=self.migration_name,
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 45, in changes
changes = self._detect_changes(convert_apps, graph)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 128, in _detect_changes
self.old_apps = self.from_state.concrete_apps
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/migrations/state.py", line 166, in concrete_apps
self.apps = StateApps(self.real_apps, self.models, ignore_swappable=True)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/migrations/state.py", line 228, in __init__
self.render_multiple(list(models.values()) + self.real_models)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/migrations/state.py", line 296, in render_multiple
model.render(self)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/migrations/state.py", line 585, in render
body,
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/models/base.py", line 158, in __new__
new_class.add_to_class(obj_name, obj)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/models/base.py", line 299, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/models/fields/related.py", line 702, in contribute_to_class
super(ForeignObject, self).contribute_to_class(cls, name, virtual_only=virtual_only)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/models/fields/related.py", line 308, in contribute_to_class
lazy_related_operation(resolve_related_class, cls, self.remote_field.model, field=self)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/models/fields/related.py", line 85, in lazy_related_operation
return apps.lazy_model_operation(partial(function, **kwargs), *model_keys)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/models/fields/related.py", line 83, in <genexpr>
model_keys = (make_model_tuple(m) for m in models)
File "/Users/reonard/.virtualenvs/django-ito/lib/python2.7/site-packages/django/db/models/utils.py", line 14, in make_model_tuple
app_label, model_name = model.split(".")
ValueError: too many values to unpack
I added a print statement for the model splitted and the output was:
auth.User
auth.Group_permissions
auth.User_groups
auth.User_user_permissions
app.ticketmgr.BasePriority
It appears that the "app.ticketmgr.BasePriority" has an extra "dot". Actually the app name is "ticketmgr" but put in an "app" folder for better managerment. May i know what should i do to make the migrations work? is there any extra settings should be done to support putting serveral apps in a "app" folder ?
Below is my app folder, there are 2 apps (comm, ticketmgr) in it.
|____app
| |______init__.py
| |____comm
| | |______init__.py
| | |____admin.py
| | |____apps.py
| | |____migrations
| | | |______init__.py
| | |____models.py
| | |____role_required.py
| | |____tests.py
| | |____views.py
| |____ticketmgr
| | |______init__.py
| | |____admin.py
| | |____apps.py
| | |____forms.py
| | |____migrations
| | | |____0001_initial.py
| | | |______init__.py
| | |____models.py
| | |____tests.py
| | |____views.py
Nothing more is needed. Just add "app.ticketmgr", "app.comm" to INSTALLED_APPS.
BasePriority does not appear in your project directories. Maybe it's a model?
The installed app line should be:
app.ticketmgr
Since BasePriority does not exists, django gets 3 arguments instead of the 2 required for app_label,model_name. The "BasePriority" is the third argument, which excepts.
Related
OS: Windows 10
Now, for the project where the runserver command works I get this:
Here is my project structure. i have install all the requirements for this project but still getting this error. I've found something where there were errors with the run server command, but none were satisfying. If this is a duplicate, I do apologies, but I'm pretty sure it isn't. If there's a need for other files and snippets of code, I'll put here everything. Thank you so much.
D:.
| main.py
|
| README.md
|
+---BLL
| | asgi.py
| | requirements.txt
| | settings.py
| | urls.py
| | wsgi.py
| | __init__.py
| |
| \---__pycache__
| settings.cpython-37.pyc
| settings.cpython-39.pyc
| urls.cpython-37.pyc
| urls.cpython-39.pyc
| __init__.cpython-37.pyc
| __init__.cpython-39.pyc
|
+---DAL
| | db.sqlite3
| | __init__.py
| |
| +---account
| | | admin.py
| | | apps.py
| | | forms.py
| | | models.py
| | | tests.py
| | | views.py
| | | __init__.py
| | |
| | +---migrations
| | | | 0001_initial.py
| | | | __init__.py
| | | |
| | | \---__pycache__
| | | 0001_initial.cpython-38.pyc
| | | __init__.cpython-38.pyc
| | |
| | \---__pycache__
| | admin.cpython-37.pyc
| | admin.cpython-38.pyc
| | admin.cpython-39.pyc
| | apps.cpython-37.pyc
| | apps.cpython-38.pyc
| | apps.cpython-39.pyc
| | forms.cpython-38.pyc
| | models.cpython-37.pyc
| | models.cpython-38.pyc
| | models.cpython-39.pyc
| | views.cpython-38.pyc
| | __init__.cpython-37.pyc
| | __init__.cpython-38.pyc
| | __init__.cpython-39.pyc
| |
| \---chatbot
| | admin.py
| | apps.py
| | data.pickle
| | loadAI.py
| | models.py
| | session.json
| | tests.py
| | trainAI.py
| | views.py
| | __init__.py
| |
| +---migrations
| | 0001_initial.py
| | __init__.py
| |
| +---model
| | testmodel.h5
| |
| \---__pycache__
| admin.cpython-37.pyc
| admin.cpython-39.pyc
| apps.cpython-37.pyc
| apps.cpython-39.pyc
| models.cpython-37.pyc
| models.cpython-39.pyc
| trainAI.cpython-37.pyc
| trainAI.cpython-39.pyc
| views.cpython-37.pyc
| views.cpython-39.pyc
| __init__.cpython-37.pyc
| __init__.cpython-39.pyc
|
+---TESTS
| test.py
|
\---UI
| admin.py
| apps.py
| models.py
| tests.py
| urls.py
| views.py
| __init__.py
|
+---images
| 1.PNG
| 10.PNG
| 2.PNG
| 3.PNG
| 4.PNG
| 5.PNG
| 6.PNG
| 7.PNG
| 8.PNG
| 9.PNG
| chatbot.GIF
|
+---static
| \---UI
| +---audio
| | audio0.mp3
| | audio1.mp3
| | audio2.mp3
| | audio3.mp3
| |
| +---css
| | css-main.css
| | css-responsive.css
| |
| \---images
| bg.jpg
| landscape1.jpg
| logo.ico
| logo.jpg
| user.png
|
+---templates
| \---UI
| | base.html
| | index.html
| |
| +---errors
| | 404.html
| | 500.html
| |
| \---pages
| about.html
| account.html
| changepass-done.html
| changepass.html
| chatbot.html
| FAQs.html
| login.html
| signup.html
| update.html
|
\---__pycache__
admin.cpython-37.pyc
admin.cpython-39.pyc
apps.cpython-37.pyc
apps.cpython-39.pyc
models.cpython-37.pyc
models.cpython-39.pyc
urls.cpython-37.pyc
urls.cpython-39.pyc
views.cpython-37.pyc
views.cpython-39.pyc
__init__.cpython-37.pyc
__init__.cpython-39.pyc
I have clone this project from git hub when i use python main.py runserver command it givs me this error:
D:\Covid19Chatbot-master>python main.py runserver
Watching for file changes with StatReloader
Performing system checks...
2021-01-22 17:20:47.257952: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2021-01-22 17:20:47.263540: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
[nltk_data] Downloading package punkt to
[nltk_data] C:\Users\mehra\AppData\Roaming\nltk_data...
[nltk_data] Package punkt is already up-to-date!
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\threading.py", line 926, in _bootstrap_inner
self.run()
File "C:\ProgramData\Anaconda3\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\management\base.py", line 395, in check
include_deployment_checks=include_deployment_checks,
File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\management\base.py", line 382, in _run_checks
return checks.run_checks(**kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\ProgramData\Anaconda3\lib\site-packages\django\urls\resolvers.py", line 407, in check
for pattern in self.url_patterns:
File "C:\ProgramData\Anaconda3\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\urls\resolvers.py", line 588, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\ProgramData\Anaconda3\lib\site-packages\django\urls\resolvers.py", line 581, in urlconf_module
return import_module(self.urlconf_name)
File "C:\ProgramData\Anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "D:\Covid19Chatbot-master\BLL\urls.py", line 21, in <module>
path('', include('UI.urls')),
File "C:\ProgramData\Anaconda3\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\ProgramData\Anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "D:\Covid19Chatbot-master\UI\urls.py", line 4, in <module>
from chatbot.views import (
File "D:\Covid19Chatbot-master\DAL\chatbot\views.py", line 6, in <module>
ai = TrainAI()
File "D:\Covid19Chatbot-master\DAL\chatbot\trainAI.py", line 24, in __init__
jsonContent = json.loads(res.content.decode())
File "C:\ProgramData\Anaconda3\lib\json\__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
The Error is from Lines 22-24 in trainAI
website = r"https://coronavirus-ph-api.herokuapp.com/total/"
res = requests.get(website)
jsonContent = json.loads(res.content.decode())
this website has no content and returns no json, thats why it cannot iterate through it and throws an error
I want to get a django app running using djongo with mongo, and docker.
My setup looks like this:
docker-compose.yml
version: '3.7'
services:
webserver:
build:
context: .
ports:
- "8000:8000"
volumes:
- ./webserver:/webserver
command: sh -c "python manage.py runserver 0.0.0.0:8000"
environment:
- DEBUG=1
links:
- mongo
depends_on:
- migration
mongo:
image: mongo:latest
restart: unless-stopped
volumes:
- ./mongo/data/db:/data/db
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: mongoadmin
MONGO_INITDB_DATABASE: raspicam
ports:
- "27017:27017"
migration:
build: .
image: app
command: sh -c "python manage.py migrate"
volumes:
- ./webserver:/webserver
links:
- mongo
depends_on:
- make_migrations
make_migrations:
build: .
image: app
command: sh -c "python manage.py makemigrations"
volumes:
- ./webserver:/webserver
links:
- mongo
depends_on:
- mongo
Dockerfile:
FROM python:3.8-alpine
ENV PATH="/scripts:${PATH}"
ENV LIBRARY_PATH=/lib:/usr/lib
COPY ./requirements.txt /requirements.txt
RUN apk add --update --no-cache --virtual .tmp gcc libc-dev linux-headers jpeg-dev libjpeg-turbo
RUN apk add build-base python3-dev zlib-dev
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r /requirements.txt
RUN apk add libjpeg
RUN apk del .tmp
RUN mkdir /webserver
COPY ./webserver /webserver
WORKDIR /webserver
COPY ./scripts /scripts
RUN chmod +x /scripts/*
RUN mkdir -p /vol/web/media
RUN mkdir -p /vol/web/
RUN adduser -D user
RUN chown -R user:user /vol
RUN chmod -R 755 /vol/web
USER user
CMD ["entrypoint.sh"]
settings.py
DATABASES = {
"default": {
"ENGINE": "djongo",
"NAME": "raspicam",
"CLIENT": {
"host": "mongodb://mongodb:27017",
"username": "root",
"password": "mongoadmin",
"authSource": "admin",
"authMechanism": "SCRAM-SHA-1",
},
}
}
I already test on my local and it works.
but I try to dockerizing it. The issue is that when I 'docker-compose up' I get the following error.
Creating server_mongo_1 ... done
Creating server_make_migrations_1 ... done
Creating server_migration_1 ... done
Creating server_webserver_1 ... done
mongo_1 | Successfully added user: {
mongo_1 | "user" : "root",
mongo_1 | "roles" : [
mongo_1 | {
mongo_1 | "role" : "root",
mongo_1 | "db" : "admin"
mongo_1 | }
mongo_1 | ]
mongo_1 | }
mongo_1 | Error saving history file: FileOpenFailed Unable to open() file /home/mongodb/.dbshell: No such file or directory
make_migrations_1 | Traceback (most recent call last):
make_migrations_1 | File "manage.py", line 21, in <module>
make_migrations_1 | main()
make_migrations_1 | File "manage.py", line 17, in main
make_migrations_1 | execute_from_command_line(sys.argv)
make_migrations_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
make_migrations_1 | utility.execute()
make_migrations_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 375, in execute
make_migrations_1 | self.fetch_command(subcommand).run_from_argv(self.argv)
make_migrations_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 323, in run_from_argv
make_migrations_1 | self.execute(*args, **cmd_options)
make_migrations_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 364, in execute
make_migrations_1 | output = self.handle(*args, **options)
make_migrations_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 83, in wrapped
make_migrations_1 | res = handle_func(*args, **kwargs)
make_migrations_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/makemigrations.py", line 101, in handle
make_migrations_1 | loader.check_consistent_history(connection)
make_migrations_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/loader.py", line 283, in check_consistent_history
make_migrations_1 | applied = recorder.applied_migrations()
make_migrations_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 73, in applied_migrations
make_migrations_1 | if self.has_table():
make_migrations_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 56, in has_table
make_migrations_1 | return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
make_migrations_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/introspection.py", line 48, in table_names
make_migrations_1 | return get_names(cursor)
make_migrations_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/introspection.py", line 43, in get_names
make_migrations_1 | return sorted(ti.name for ti in self.get_table_list(cursor)
make_migrations_1 | File "/usr/local/lib/python3.8/site-packages/djongo/introspection.py", line 47, in get_table_list
make_migrations_1 | for c in cursor.db_conn.list_collection_names()
make_migrations_1 | File "/usr/local/lib/python3.8/site-packages/pymongo/database.py", line 863, in list_collection_names
make_migrations_1 | for result in self.list_collections(session=session, **kwargs)]
make_migrations_1 | File "/usr/local/lib/python3.8/site-packages/pymongo/database.py", line 825, in list_collections
make_migrations_1 | return self.__client._retryable_read(
make_migrations_1 | File "/usr/local/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1460, in _retryable_read
make_migrations_1 | server = self._select_server(
make_migrations_1 | File "/usr/local/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1278, in _select_server
make_migrations_1 | server = topology.select_server(server_selector)
make_migrations_1 | File "/usr/local/lib/python3.8/site-packages/pymongo/topology.py", line 241, in select_server
make_migrations_1 | return random.choice(self.select_servers(selector,
make_migrations_1 | File "/usr/local/lib/python3.8/site-packages/pymongo/topology.py", line 199, in select_servers
make_migrations_1 | server_descriptions = self._select_servers_loop(
make_migrations_1 | File "/usr/local/lib/python3.8/site-packages/pymongo/topology.py", line 215, in _select_servers_loop
make_migrations_1 | raise ServerSelectionTimeoutError(
make_migrations_1 | pymongo.errors.ServerSelectionTimeoutError: mongodb:27017: [Errno -2] Name does not resolve, Timeout: 30s, Topology Description: <TopologyDescription id: 5fb23c4bc9495116fef1072a, topology_type: Single, servers: [<ServerDescription ('mongodb', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('mongodb:27017: [Errno -2] Name does not resolve')>]>
migration_1 | Traceback (most recent call last):
migration_1 | File "manage.py", line 21, in <module>
migration_1 | main()
migration_1 | File "manage.py", line 17, in main
migration_1 | execute_from_command_line(sys.argv)
migration_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
migration_1 | utility.execute()
migration_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 375, in execute
migration_1 | self.fetch_command(subcommand).run_from_argv(self.argv)
migration_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 323, in run_from_argv
migration_1 | self.execute(*args, **cmd_options)
migration_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 364, in execute
migration_1 | output = self.handle(*args, **options)
migration_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 83, in wrapped
migration_1 | res = handle_func(*args, **kwargs)
migration_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 87, in handle
migration_1 | executor = MigrationExecutor(connection, self.migration_progress_callback)
migration_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/executor.py", line 18, in __init__
migration_1 | self.loader = MigrationLoader(self.connection)
migration_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/loader.py", line 49, in __init__
migration_1 | self.build_graph()
migration_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/loader.py", line 212, in build_graph
migration_1 | self.applied_migrations = recorder.applied_migrations()
migration_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 73, in applied_migrations
migration_1 | if self.has_table():
migration_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 56, in has_table
migration_1 | return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
migration_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/introspection.py", line 48, in table_names
migration_1 | return get_names(cursor)
migration_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/introspection.py", line 43, in get_names
migration_1 | return sorted(ti.name for ti in self.get_table_list(cursor)
migration_1 | File "/usr/local/lib/python3.8/site-packages/djongo/introspection.py", line 47, in get_table_list
migration_1 | for c in cursor.db_conn.list_collection_names()
migration_1 | File "/usr/local/lib/python3.8/site-packages/pymongo/database.py", line 863, in list_collection_names
migration_1 | for result in self.list_collections(session=session, **kwargs)]
migration_1 | File "/usr/local/lib/python3.8/site-packages/pymongo/database.py", line 825, in list_collections
migration_1 | return self.__client._retryable_read(
migration_1 | File "/usr/local/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1460, in _retryable_read
migration_1 | server = self._select_server(
migration_1 | File "/usr/local/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1278, in _select_server
migration_1 | server = topology.select_server(server_selector)
migration_1 | File "/usr/local/lib/python3.8/site-packages/pymongo/topology.py", line 241, in select_server
migration_1 | return random.choice(self.select_servers(selector,
migration_1 | File "/usr/local/lib/python3.8/site-packages/pymongo/topology.py", line 199, in select_servers
migration_1 | server_descriptions = self._select_servers_loop(
migration_1 | File "/usr/local/lib/python3.8/site-packages/pymongo/topology.py", line 215, in _select_servers_loop
migration_1 | raise ServerSelectionTimeoutError(
migration_1 | pymongo.errors.ServerSelectionTimeoutError: mongodb:27017: [Errno -2] Name does not resolve, Timeout: 30s, Topology Description: <TopologyDescription id: 5fb23c4c69a8bce7b564bf46, topology_type: Single, servers: [<ServerDescription ('mongodb', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('mongodb:27017: [Errno -2] Name does not resolve')>]>
server_make_migrations_1 exited with code 1
server_migration_1 exited with code 1
webserver_1 | Exception in thread django-main-thread:
webserver_1 | Traceback (most recent call last):
webserver_1 | File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
webserver_1 | self.run()
webserver_1 | File "/usr/local/lib/python3.8/threading.py", line 870, in run
webserver_1 | self._target(*self._args, **self._kwargs)
webserver_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/autoreload.py", line 54, in wrapper
webserver_1 | fn(*args, **kwargs)
webserver_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 120, in inner_run
webserver_1 | self.check_migrations()
webserver_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 453, in check_migrations
webserver_1 | executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
webserver_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/executor.py", line 18, in __init__
webserver_1 | self.loader = MigrationLoader(self.connection)
webserver_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/loader.py", line 49, in __init__
webserver_1 | self.build_graph()
webserver_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/loader.py", line 212, in build_graph
webserver_1 | self.applied_migrations = recorder.applied_migrations()
webserver_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 73, in applied_migrations
webserver_1 | if self.has_table():
webserver_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 56, in has_table
webserver_1 | return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
webserver_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/introspection.py", line 48, in table_names
webserver_1 | return get_names(cursor)
webserver_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/introspection.py", line 43, in get_names
webserver_1 | return sorted(ti.name for ti in self.get_table_list(cursor)
webserver_1 | File "/usr/local/lib/python3.8/site-packages/djongo/introspection.py", line 47, in get_table_list
webserver_1 | for c in cursor.db_conn.list_collection_names()
webserver_1 | File "/usr/local/lib/python3.8/site-packages/pymongo/database.py", line 863, in list_collection_names
webserver_1 | for result in self.list_collections(session=session, **kwargs)]
webserver_1 | File "/usr/local/lib/python3.8/site-packages/pymongo/database.py", line 825, in list_collections
webserver_1 | return self.__client._retryable_read(
webserver_1 | File "/usr/local/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1460, in _retryable_read
webserver_1 | server = self._select_server(
webserver_1 | File "/usr/local/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1278, in _select_server
webserver_1 | server = topology.select_server(server_selector)
webserver_1 | File "/usr/local/lib/python3.8/site-packages/pymongo/topology.py", line 241, in select_server
webserver_1 | return random.choice(self.select_servers(selector,
webserver_1 | File "/usr/local/lib/python3.8/site-packages/pymongo/topology.py", line 199, in select_servers
webserver_1 | server_descriptions = self._select_servers_loop(
webserver_1 | File "/usr/local/lib/python3.8/site-packages/pymongo/topology.py", line 215, in _select_servers_loop
webserver_1 | raise ServerSelectionTimeoutError(
webserver_1 | pymongo.errors.ServerSelectionTimeoutError: mongodb:27017: [Errno -2] Name does not resolve, Timeout: 30s, Topology Description: <TopologyDescription id: 5fb23c4d6fa2c64607ec6aee, topology_type: Single, servers: [<ServerDescription ('mongodb', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('mongodb:27017: [Errno -2] Name does not resolve')>]>
How can I solve this problem....
p.s what does this picture means?! is mongo working with docker?!
enter image description here
I have completed my Django Project using cookiecutter-django.
If I just locally run:
$ docker-compose -f local.yml build
$ docker-compose -f local.yml up
My project launches just fine in http://0.0.0.0:8000
Nonetheless, now I am trying to deploy it following this guide: https://realpython.com/development-and-deployment-of-cookiecutter-django-via-docker/
I have been able to create the local docker-machine with docker-machine create --driver virtualbox dev, activate it eval $(docker-machine env dev) and build the image, but if I run docker-compose -f local.yml up then I get the following error:
Attaching to innovacion_innsai_postgres_1, innovacion_innsai_django_1, innovacion_innsai_node_1
postgres_1 | 2020-03-12 09:14:42.686 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres_1 | 2020-03-12 09:14:42.686 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgres_1 | 2020-03-12 09:14:42.688 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1 | 2020-03-12 09:14:42.702 UTC [21] LOG: database system was shut down at 2020-03-11 10:05:23 UTC
postgres_1 | 2020-03-12 09:14:42.732 UTC [1] LOG: database system is ready to accept connections
django_1 | PostgreSQL is available
django_1 | Traceback (most recent call last):
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
django_1 | return self.cursor.execute(sql, params)
django_1 | psycopg2.errors.UndefinedTable: relation "innovation_sector" does not exist
django_1 | LINE 1: ...n_sector"."id", "innovation_sector"."sector" FROM "innovatio...
django_1 | ^
django_1 |
django_1 |
django_1 | The above exception was the direct cause of the following exception:
django_1 |
django_1 | Traceback (most recent call last):
django_1 | File "manage.py", line 30, in <module>
django_1 | execute_from_command_line(sys.argv)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
django_1 | utility.execute()
django_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
django_1 | self.fetch_command(subcommand).run_from_argv(self.argv)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
django_1 | self.execute(*args, **cmd_options)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 361, in execute
django_1 | self.check()
django_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 390, in check
django_1 | include_deployment_checks=include_deployment_checks,
django_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 65, in _run_checks
django_1 | issues.extend(super()._run_checks(**kwargs))
django_1 | File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 377, in _run_checks
django_1 | return checks.run_checks(**kwargs)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/core/checks/registry.py", line 72, in run_checks
django_1 | new_errors = check(app_configs=app_configs)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/core/checks/urls.py", line 13, in check_url_config
django_1 | return check_resolver(resolver)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/core/checks/urls.py", line 23, in check_resolver
django_1 | return check_method()
django_1 | File "/usr/local/lib/python3.7/site-packages/django/urls/resolvers.py", line 399, in check
django_1 | for pattern in self.url_patterns:
django_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
django_1 | res = instance.__dict__[self.name] = self.func(instance)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/urls/resolvers.py", line 584, in url_patterns
django_1 | patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
django_1 | res = instance.__dict__[self.name] = self.func(instance)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/urls/resolvers.py", line 577, in urlconf_module
django_1 | return import_module(self.urlconf_name)
django_1 | File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
django_1 | return _bootstrap._gcd_import(name[level:], package, level)
django_1 | File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
django_1 | File "<frozen importlib._bootstrap>", line 983, in _find_and_load
django_1 | File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
django_1 | File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
django_1 | File "<frozen importlib._bootstrap_external>", line 728, in exec_module
django_1 | File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
django_1 | File "/app/config/urls.py", line 18, in <module>
django_1 | path("", include("innovacion_innsai.innovation.urls", namespace="innovation")),
django_1 | File "/usr/local/lib/python3.7/site-packages/django/urls/conf.py", line 34, in include
django_1 | urlconf_module = import_module(urlconf_module)
django_1 | File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
django_1 | return _bootstrap._gcd_import(name[level:], package, level)
django_1 | File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
django_1 | File "<frozen importlib._bootstrap>", line 983, in _find_and_load
django_1 | File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
django_1 | File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
django_1 | File "<frozen importlib._bootstrap_external>", line 728, in exec_module
django_1 | File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
django_1 | File "/app/innovacion_innsai/innovation/urls.py", line 2, in <module>
django_1 | from innovacion_innsai.innovation import views
django_1 | File "/app/innovacion_innsai/innovation/views.py", line 9, in <module>
django_1 | from .analytics import alimentacion_cases, agro_cases, turismo_cases, movilidad_cases
django_1 | File "/app/innovacion_innsai/innovation/analytics.py", line 17, in <module>
django_1 | for case in Case.objects.filter(sector__sector=sectors[0]):
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/models/query.py", line 308, in __getitem__
django_1 | qs._fetch_all()
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/models/query.py", line 1242, in _fetch_all
django_1 | self._result_cache = list(self._iterable_class(self))
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/models/query.py", line 55, in __iter__
django_1 | results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1133, in execute_sql
django_1 | cursor.execute(sql, params)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 99, in execute
django_1 | return super().execute(sql, params)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 67, in execute
django_1 | return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
django_1 | return executor(sql, params, many, context)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
django_1 | return self.cursor.execute(sql, params)
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/utils.py", line 89, in __exit__
django_1 | raise dj_exc_value.with_traceback(traceback) from exc_value
django_1 | File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
django_1 | return self.cursor.execute(sql, params)
django_1 | django.db.utils.ProgrammingError: relation "innovation_sector" does not exist
django_1 | LINE 1: ...n_sector"."id", "innovation_sector"."sector" FROM "innovatio...
django_1 | ^
django_1 |
innovacion_innsai_django_1 exited with code 1
node_1 |
node_1 | > innovacion_innsai#1.1.0 dev /app
node_1 | > gulp
node_1 |
node_1 | [09:14:48] Using gulpfile /app/gulpfile.js
node_1 | [09:14:48] Starting 'default'...
node_1 | [09:14:48] Starting 'styles'...
node_1 | [09:14:48] Starting 'scripts'...
node_1 | [09:14:48] Starting 'imgCompression'...
node_1 | [09:14:48] gulp-imagemin: Minified 0 images
node_1 | [09:14:48] Finished 'imgCompression' after 34 ms
node_1 | [09:14:48] Finished 'scripts' after 128 ms
node_1 | [09:14:49] Finished 'styles' after 1.09 s
node_1 | [09:14:49] Starting 'initBrowserSync'...
node_1 | [09:14:49] Starting 'watchPaths'...
node_1 | [Browsersync] Proxying: http://django:8000
node_1 | [Browsersync] Access URLs:
node_1 | -----------------------------------
node_1 | Local: http://localhost:3000
node_1 | External: http://172.20.0.4:3000
node_1 | -----------------------------------
node_1 | UI: http://localhost:3001
node_1 | UI External: http://localhost:3001
node_1 | -----------------------------------
In case it might be relevant, if I visit the docker-machine's IP adreess and port (http://192.168.99.101:2376) before launching docker-compose build o up, the page displays "Client sent an HTTP request to an HTTPS server."
Here is my 'local.yml':
version: '3'
volumes:
local_postgres_data: {}
local_postgres_data_backups: {}
services:
django:
build:
context: .
dockerfile: ./compose/local/django/Dockerfile
image: innovacion_innsai_local_django
depends_on:
- postgres
volumes:
- .:/app
env_file:
- ./.envs/.local/.django
- ./.envs/.local/.postgres
ports:
- "8000:8000"
command: /start
postgres:
build:
context: .
dockerfile: ./compose/production/postgres/Dockerfile
image: innovacion_innsai_production_postgres
volumes:
- local_postgres_data:/var/lib/postgresql/data
- local_postgres_data_backups:/backups
env_file:
- ./.envs/.local/.postgres
node:
build:
context: .
dockerfile: ./compose/local/node/Dockerfile
image: innovacion_innsai_local_node
depends_on:
- django
volumes:
- .:/app
# http://jdlm.info/articles/2016/03/06/lessons-building-node-app-docker.html
- /app/node_modules
command: npm run dev
ports:
- "3000:3000"
# Expose browsersync UI: https://www.browsersync.io/docs/options/#option-ui
- "3001:3001"
the result of running docker-machine ls:
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
dev - virtualbox Running tcp://192.168.99.101:2376 v19.03.5
My .postgresql in the .envs/.local folder is:
# PostgreSQL
# ------------------------------------------------------------------------------
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
POSTGRES_DB=innovacion_innsai
POSTGRES_USER=debug
POSTGRES_PASSWORD=debug
and my Docker file for local:
FROM python:3.7-slim-buster
ENV PYTHONUNBUFFERED 1
RUN apt-get update \
# dependencies for building Python packages
&& apt-get install -y build-essential \
# psycopg2 dependencies
&& apt-get install -y libpq-dev \
# Translations dependencies
&& apt-get install -y gettext \
# cleaning up unused files
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& rm -rf /var/lib/apt/lists/*
# Requirements are installed here to ensure they will be cached.
COPY ./requirements /requirements
RUN pip install -r /requirements/local.txt
COPY ./compose/production/django/entrypoint /entrypoint
RUN sed -i 's/\r$//g' /entrypoint
RUN chmod +x /entrypoint
COPY ./compose/local/django/start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start
WORKDIR /app
ENTRYPOINT ["/entrypoint"]
Please, I am quite new with Django and Docker so excuse me if I did not explain myself properly. Also, please let me know if you would need any other script or information in order to take a proper look at the problem!
I dont know if you already figured this out and I don't know if I'm right but give this a try:
Instead of:
docker-compose -f local.yml up
Try:
docker-compose -f production.yml up
When you're deploying to production you should build and bring up the site with the production file not the local file.
I am trying to integrate celery version 4.2 in a django project. As per the docs I have done the changes in init.py and celery.py but when I run celery with:
python -m celery -A instaguide beat -l debug
I get the exception below. I am not sure what it is missing. The only CELERY_ setting that I have defined in my project.settings is CELERY_BROKER_URL and it doesn't complain about not connecting to broker. So it is something else that I am missing either in my settings or somewhere else. Any clues?
celery-worker | k (most recent call last):
celery-worker | File "/usr/local/lib/python2.7/runpy.py", line 174, in _run_module_as_main
celery-worker | "__main__", fname, loader, pkg_name)
celery-worker | File "/usr/local/lib/python2.7/runpy.py", line 72, in _run_code
celery-worker | exec code in run_globals
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/__main__.py", line 20, in <module>
celery-worker | main()
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/__main__.py", line 16, in main
celery-worker | _main()
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/bin/celery.py", line 322, in main
celery-worker | cmd.execute_from_commandline(argv)
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/bin/celery.py", line 496, in execute_from_commandline
celery-worker | super(CeleryCommand, self).execute_from_commandline(argv)))
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/bin/base.py", line 275, in execute_from_commandline
celery-worker | return self.handle_argv(self.prog_name, argv[1:])
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/bin/celery.py", line 488, in handle_argv
celery-worker | return self.execute(command, argv)
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/bin/celery.py", line 420, in execute
celery-worker | ).run_from_argv(self.prog_name, argv[1:], command=argv[0])
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/bin/worker.py", line 223, in run_from_argv
celery-worker | return self(*args, **options)
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/bin/base.py", line 238, in __call__
celery-worker | ret = self.run(*args, **kwargs)
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/bin/worker.py", line 257, in run
celery-worker | **kwargs)
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/worker/worker.py", line 96, in __init__
celery-worker | self.app.loader.init_worker()
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/loaders/base.py", line 114, in init_worker
celery-worker | self.import_default_modules()
celery-worker | File "/usr/local/lib/python2.7/site-packages/celery/loaders/base.py", line 108, in import_default_modules
celery-worker | raise response
celery-worker | celery.schedules.ParseException: empty filter
I figured out the problem. If one is using Default Beat Scheduler, then one needs to define the beat scheduler config with at least one scheduled tasks. Else if one is using database scheduler then it requires django-celery-beat which creates and stores the schedules in the database. So one needs to have at least 1 entry for repeatable tasks. Also the #periodic_task annotation is deprecated and going to be removed in celery-5, it doesn't seem to work.
app.conf.beat_schedule = {
# Executes every minute
'add-every-monday-morning': {
'task': 'users.tasks.test_task',
'schedule': crontab(hour="*", minute="*"),
'args': (),
},
}
I have exactly followed this tutorial (http://docs.docker.com/compose/django/) but when doing docker-compose up I get this error:
$ docker-compose up
Recreating composeexample_db_1...
Recreating composeexample_web_1...
Attaching to composeexample_db_1, composeexample_web_1
db_1 | LOG: database system was shut down at 2015-07-27 16:17:21 UTC
db_1 | LOG: MultiXact member wraparound protections are now enabled
db_1 | LOG: database system is ready to accept connections
db_1 | LOG: autovacuum launcher started
web_1 | Performing system checks...
web_1 |
web_1 | System check identified no issues (0 silenced).
web_1 | Unhandled exception in thread started by <function wrapper at 0x7f43f0126ed8>
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 225, in wrapper
web_1 | fn(*args, **kwargs)
web_1 | File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 112, in inner_run
web_1 | self.check_migrations()
web_1 | File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 164, in check_migrations
web_1 | executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
web_1 | File "/usr/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 19, in __init__
web_1 | self.loader = MigrationLoader(self.connection)
web_1 | File "/usr/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 47, in __init__
web_1 | self.build_graph()
web_1 | File "/usr/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 182, in build_graph
web_1 | self.applied_migrations = recorder.applied_migrations()
web_1 | File "/usr/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
web_1 | self.ensure_schema()
web_1 | File "/usr/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
web_1 | if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
web_1 | File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 162, in cursor
web_1 | cursor = self.make_debug_cursor(self._cursor())
web_1 | File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 135, in _cursor
web_1 | self.ensure_connection()
web_1 | File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
web_1 | self.connect()
web_1 | File "/usr/local/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
web_1 | six.reraise(dj_exc_type, dj_exc_value, traceback)
web_1 | File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
web_1 | self.connect()
web_1 | File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 119, in connect
web_1 | self.connection = self.get_new_connection(conn_params)
web_1 | File "/usr/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 176, in get_new_connection
web_1 | connection = Database.connect(**conn_params)
web_1 | File "/usr/local/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
web_1 | conn = _connect(dsn, connection_factory=connection_factory, async=async)
web_1 | django.db.utils.OperationalError: could not connect to server: No route to host
web_1 | Is the server running on host "db" (172.17.0.19) and accepting
web_1 | TCP/IP connections on port 5432?
Now, this only happens on my Fedora 21 system(kernel=4.0.4-202.fc21.x86_64) but when I spin up an Ubuntu instance in Virtualbox, it works just fine.
Any pointers?
I've run into the same issue and FWIW if you run the same command again then it works. It's almost as if "docker-compose up" brings up two containers at the same time and the django app container tries to run while postgres container is still being set up? It's mad confusing. :*(
UPDATE:
It seems that my suspicion was right, have a read at https://github.com/docker/compose/issues/374 .
Somewhat crude but a simple workaround to this race condition is to let django app container to sleep for a few seconds before running the command, so that the services that these containers depend on, e.g. PostgreSQL, are ready to accept connections. For example:
command: bash -c "sleep 3 && python manage.py runserver 0.0.0.0:8000" under django service in your yml file for docker-compose.
Another alternative is to run the django service with gunicorn or uwsgi which doesn't seem to instantiate the django application until request is received.
Hope this helps others currently fighting with docker.