Title: psycopg2.errors.UndefinedTable: relation "XXX" does not exist · Issue #45 · realpython/realpython-blog · GitHub
Open Graph Title: psycopg2.errors.UndefinedTable: relation "XXX" does not exist · Issue #45 · realpython/realpython-blog
X Title: psycopg2.errors.UndefinedTable: relation "XXX" does not exist · Issue #45 · realpython/realpython-blog
Description: First of all, thanks for this guide! 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....
Open Graph Description: First of all, thanks for this guide! 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 pro...
X Description: First of all, thanks for this guide! 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 pro...
Opengraph URL: https://github.com/realpython/realpython-blog/issues/45
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"psycopg2.errors.UndefinedTable: relation \"XXX\" does not exist","articleBody":"First of all, thanks for this guide! I have completed my Django Project using cookiecutter-django.\r\nIf I just locally run:\r\n\r\n\r\n```\r\n$ docker-compose -f local.yml build\r\n\r\n$ docker-compose -f local.yml up\r\n```\r\n\r\nMy project launches just fine in http://0.0.0.0:8000\r\n\r\nNow I am following your tutorial but I get and error when I try to run the app inside the VM. I don't know if the problem might be related to the steps in the tutorial since I didn't edit the config files since I installed cookiecutter-django.\r\n\r\nI 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:\r\n\r\n```\r\nAttaching to innovacion_innsai_postgres_1, innovacion_innsai_django_1, innovacion_innsai_node_1\r\npostgres_1 | 2020-03-12 09:14:42.686 UTC [1] LOG: listening on IPv4 address \"0.0.0.0\", port 5432\r\npostgres_1 | 2020-03-12 09:14:42.686 UTC [1] LOG: listening on IPv6 address \"::\", port 5432\r\npostgres_1 | 2020-03-12 09:14:42.688 UTC [1] LOG: listening on Unix socket \"/var/run/postgresql/.s.PGSQL.5432\"\r\npostgres_1 | 2020-03-12 09:14:42.702 UTC [21] LOG: database system was shut down at 2020-03-11 10:05:23 UTC\r\npostgres_1 | 2020-03-12 09:14:42.732 UTC [1] LOG: database system is ready to accept connections\r\ndjango_1 | PostgreSQL is available\r\ndjango_1 | Traceback (most recent call last):\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py\", line 84, in _execute\r\ndjango_1 | return self.cursor.execute(sql, params)\r\ndjango_1 | psycopg2.errors.UndefinedTable: relation \"innovation_sector\" does not exist\r\ndjango_1 | LINE 1: ...n_sector\".\"id\", \"innovation_sector\".\"sector\" FROM \"innovatio...\r\ndjango_1 | ^\r\ndjango_1 | \r\ndjango_1 | \r\ndjango_1 | The above exception was the direct cause of the following exception:\r\ndjango_1 | \r\ndjango_1 | Traceback (most recent call last):\r\ndjango_1 | File \"manage.py\", line 30, in \u003cmodule\u003e\r\ndjango_1 | execute_from_command_line(sys.argv)\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py\", line 381, in execute_from_command_line\r\ndjango_1 | utility.execute()\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py\", line 375, in execute\r\ndjango_1 | self.fetch_command(subcommand).run_from_argv(self.argv)\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/core/management/base.py\", line 323, in run_from_argv\r\ndjango_1 | self.execute(*args, **cmd_options)\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/core/management/base.py\", line 361, in execute\r\ndjango_1 | self.check()\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/core/management/base.py\", line 390, in check\r\ndjango_1 | include_deployment_checks=include_deployment_checks,\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/core/management/commands/migrate.py\", line 65, in _run_checks\r\ndjango_1 | issues.extend(super()._run_checks(**kwargs))\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/core/management/base.py\", line 377, in _run_checks\r\ndjango_1 | return checks.run_checks(**kwargs)\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/core/checks/registry.py\", line 72, in run_checks\r\ndjango_1 | new_errors = check(app_configs=app_configs)\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/core/checks/urls.py\", line 13, in check_url_config\r\ndjango_1 | return check_resolver(resolver)\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/core/checks/urls.py\", line 23, in check_resolver\r\ndjango_1 | return check_method()\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/urls/resolvers.py\", line 399, in check\r\ndjango_1 | for pattern in self.url_patterns:\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/utils/functional.py\", line 80, in __get__\r\ndjango_1 | res = instance.__dict__[self.name] = self.func(instance)\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/urls/resolvers.py\", line 584, in url_patterns\r\ndjango_1 | patterns = getattr(self.urlconf_module, \"urlpatterns\", self.urlconf_module)\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/utils/functional.py\", line 80, in __get__\r\ndjango_1 | res = instance.__dict__[self.name] = self.func(instance)\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/urls/resolvers.py\", line 577, in urlconf_module\r\ndjango_1 | return import_module(self.urlconf_name)\r\ndjango_1 | File \"/usr/local/lib/python3.7/importlib/__init__.py\", line 127, in import_module\r\ndjango_1 | return _bootstrap._gcd_import(name[level:], package, level)\r\ndjango_1 | File \"\u003cfrozen importlib._bootstrap\u003e\", line 1006, in _gcd_import\r\ndjango_1 | File \"\u003cfrozen importlib._bootstrap\u003e\", line 983, in _find_and_load\r\ndjango_1 | File \"\u003cfrozen importlib._bootstrap\u003e\", line 967, in _find_and_load_unlocked\r\ndjango_1 | File \"\u003cfrozen importlib._bootstrap\u003e\", line 677, in _load_unlocked\r\ndjango_1 | File \"\u003cfrozen importlib._bootstrap_external\u003e\", line 728, in exec_module\r\ndjango_1 | File \"\u003cfrozen importlib._bootstrap\u003e\", line 219, in _call_with_frames_removed\r\ndjango_1 | File \"/app/config/urls.py\", line 18, in \u003cmodule\u003e\r\ndjango_1 | path(\"\", include(\"innovacion_innsai.innovation.urls\", namespace=\"innovation\")),\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/urls/conf.py\", line 34, in include\r\ndjango_1 | urlconf_module = import_module(urlconf_module)\r\ndjango_1 | File \"/usr/local/lib/python3.7/importlib/__init__.py\", line 127, in import_module\r\ndjango_1 | return _bootstrap._gcd_import(name[level:], package, level)\r\ndjango_1 | File \"\u003cfrozen importlib._bootstrap\u003e\", line 1006, in _gcd_import\r\ndjango_1 | File \"\u003cfrozen importlib._bootstrap\u003e\", line 983, in _find_and_load\r\ndjango_1 | File \"\u003cfrozen importlib._bootstrap\u003e\", line 967, in _find_and_load_unlocked\r\ndjango_1 | File \"\u003cfrozen importlib._bootstrap\u003e\", line 677, in _load_unlocked\r\ndjango_1 | File \"\u003cfrozen importlib._bootstrap_external\u003e\", line 728, in exec_module\r\ndjango_1 | File \"\u003cfrozen importlib._bootstrap\u003e\", line 219, in _call_with_frames_removed\r\ndjango_1 | File \"/app/innovacion_innsai/innovation/urls.py\", line 2, in \u003cmodule\u003e\r\ndjango_1 | from innovacion_innsai.innovation import views\r\ndjango_1 | File \"/app/innovacion_innsai/innovation/views.py\", line 9, in \u003cmodule\u003e\r\ndjango_1 | from .analytics import alimentacion_cases, agro_cases, turismo_cases, movilidad_cases\r\ndjango_1 | File \"/app/innovacion_innsai/innovation/analytics.py\", line 17, in \u003cmodule\u003e\r\ndjango_1 | for case in Case.objects.filter(sector__sector=sectors[0]):\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/db/models/query.py\", line 308, in __getitem__\r\ndjango_1 | qs._fetch_all()\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/db/models/query.py\", line 1242, in _fetch_all\r\ndjango_1 | self._result_cache = list(self._iterable_class(self))\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/db/models/query.py\", line 55, in __iter__\r\ndjango_1 | results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/db/models/sql/compiler.py\", line 1133, in execute_sql\r\ndjango_1 | cursor.execute(sql, params)\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py\", line 99, in execute\r\ndjango_1 | return super().execute(sql, params)\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py\", line 67, in execute\r\ndjango_1 | return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py\", line 76, in _execute_with_wrappers\r\ndjango_1 | return executor(sql, params, many, context)\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py\", line 84, in _execute\r\ndjango_1 | return self.cursor.execute(sql, params)\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/db/utils.py\", line 89, in __exit__\r\ndjango_1 | raise dj_exc_value.with_traceback(traceback) from exc_value\r\ndjango_1 | File \"/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py\", line 84, in _execute\r\ndjango_1 | return self.cursor.execute(sql, params)\r\ndjango_1 | django.db.utils.ProgrammingError: relation \"innovation_sector\" does not exist\r\ndjango_1 | LINE 1: ...n_sector\".\"id\", \"innovation_sector\".\"sector\" FROM \"innovatio...\r\ndjango_1 | ^\r\ndjango_1 | \r\ninnovacion_innsai_django_1 exited with code 1\r\nnode_1 | \r\nnode_1 | \u003e innovacion_innsai@1.1.0 dev /app\r\nnode_1 | \u003e gulp\r\nnode_1 | \r\nnode_1 | [09:14:48] Using gulpfile /app/gulpfile.js\r\nnode_1 | [09:14:48] Starting 'default'...\r\nnode_1 | [09:14:48] Starting 'styles'...\r\nnode_1 | [09:14:48] Starting 'scripts'...\r\nnode_1 | [09:14:48] Starting 'imgCompression'...\r\nnode_1 | [09:14:48] gulp-imagemin: Minified 0 images\r\nnode_1 | [09:14:48] Finished 'imgCompression' after 34 ms\r\nnode_1 | [09:14:48] Finished 'scripts' after 128 ms\r\nnode_1 | [09:14:49] Finished 'styles' after 1.09 s\r\nnode_1 | [09:14:49] Starting 'initBrowserSync'...\r\nnode_1 | [09:14:49] Starting 'watchPaths'...\r\nnode_1 | [Browsersync] Proxying: http://django:8000\r\nnode_1 | [Browsersync] Access URLs:\r\nnode_1 | -----------------------------------\r\nnode_1 | Local: http://localhost:3000\r\nnode_1 | External: http://172.20.0.4:3000\r\nnode_1 | -----------------------------------\r\nnode_1 | UI: http://localhost:3001\r\nnode_1 | UI External: http://localhost:3001\r\nnode_1 | -----------------------------------\r\n\r\n```\r\n\r\n\r\nIn 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.\"\r\n\r\nHere is my 'local.yml':\r\n\r\n```\r\nversion: '3'\r\n\r\nvolumes:\r\n local_postgres_data: {}\r\n local_postgres_data_backups: {}\r\n\r\nservices:\r\n django:\r\n build:\r\n context: .\r\n dockerfile: ./compose/local/django/Dockerfile\r\n image: innovacion_innsai_local_django\r\n depends_on:\r\n - postgres\r\n volumes:\r\n - .:/app\r\n env_file:\r\n - ./.envs/.local/.django\r\n - ./.envs/.local/.postgres\r\n ports:\r\n - \"8000:8000\"\r\n command: /start\r\n\r\n postgres:\r\n build:\r\n context: .\r\n dockerfile: ./compose/production/postgres/Dockerfile\r\n image: innovacion_innsai_production_postgres\r\n volumes:\r\n - local_postgres_data:/var/lib/postgresql/data\r\n - local_postgres_data_backups:/backups\r\n env_file:\r\n - ./.envs/.local/.postgres\r\n\r\n node:\r\n build:\r\n context: .\r\n dockerfile: ./compose/local/node/Dockerfile\r\n image: innovacion_innsai_local_node\r\n depends_on:\r\n - django\r\n volumes:\r\n - .:/app\r\n # http://jdlm.info/articles/2016/03/06/lessons-building-node-app-docker.html\r\n - /app/node_modules\r\n command: npm run dev\r\n ports:\r\n - \"3000:3000\"\r\n # Expose browsersync UI: https://www.browsersync.io/docs/options/#option-ui\r\n - \"3001:3001\"\r\n```\r\n\r\nthe result of running docker-machine ls:\r\n\r\n```\r\nNAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS\r\ndev - virtualbox Running tcp://192.168.99.101:2376 v19.03.5 \r\n```\r\n\r\nMy .postgresql in the .envs/.local folder is:\r\n\r\n```\r\n# PostgreSQL\r\n# ------------------------------------------------------------------------------\r\nPOSTGRES_HOST=postgres\r\nPOSTGRES_PORT=5432\r\nPOSTGRES_DB=innovacion_innsai\r\nPOSTGRES_USER=debug\r\nPOSTGRES_PASSWORD=debug\r\n```\r\n\r\n\r\nand my Docker file for local:\r\n\r\n```\r\nFROM python:3.7-slim-buster\r\n\r\nENV PYTHONUNBUFFERED 1\r\n\r\nRUN apt-get update \\\r\n # dependencies for building Python packages\r\n \u0026\u0026 apt-get install -y build-essential \\\r\n # psycopg2 dependencies\r\n \u0026\u0026 apt-get install -y libpq-dev \\\r\n # Translations dependencies\r\n \u0026\u0026 apt-get install -y gettext \\\r\n # cleaning up unused files\r\n \u0026\u0026 apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \\\r\n \u0026\u0026 rm -rf /var/lib/apt/lists/*\r\n\r\n# Requirements are installed here to ensure they will be cached.\r\nCOPY ./requirements /requirements\r\nRUN pip install -r /requirements/local.txt\r\n\r\nCOPY ./compose/production/django/entrypoint /entrypoint\r\nRUN sed -i 's/\\r$//g' /entrypoint\r\nRUN chmod +x /entrypoint\r\n\r\nCOPY ./compose/local/django/start /start\r\nRUN sed -i 's/\\r$//g' /start\r\nRUN chmod +x /start\r\n\r\nWORKDIR /app\r\n\r\nENTRYPOINT [\"/entrypoint\"]\r\n```\r\n\r\n","author":{"url":"https://github.com/joserraec","@type":"Person","name":"joserraec"},"datePublished":"2020-03-13T10:17:31.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/45/realpython-blog/issues/45"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:781da66f-3fe2-948f-1d60-2747647b0cb9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D714:C8602:1BBDCD0:24A5888:6971A190 |
| html-safe-nonce | 67e5d9a82925b4d555fe8a31984b3269c83ff1dc604e14fa0a0747bde4562bc4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzE0OkM4NjAyOjFCQkRDRDA6MjRBNTg4ODo2OTcxQTE5MCIsInZpc2l0b3JfaWQiOiI4OTU2MDk3ODgxNjUxMTI2NjcyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b6abca1b284444679691684a0a627a92606acf59242413151e2318d781075048 |
| hovercard-subject-tag | issue:580502121 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/realpython/realpython-blog/45/issue_layout |
| twitter:image | https://opengraph.githubassets.com/831ac3936aad55862c6188765cadcaf4d930d933d0d77b2fb4cd4e485b3c18cb/realpython/realpython-blog/issues/45 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/831ac3936aad55862c6188765cadcaf4d930d933d0d77b2fb4cd4e485b3c18cb/realpython/realpython-blog/issues/45 |
| og:image:alt | First of all, thanks for this guide! 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 pro... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | joserraec |
| hostname | github.com |
| expected-hostname | github.com |
| None | fdfdce9cd4f6ab85dca2b0d11264270829297c962dd5a79df449062d7822258f |
| turbo-cache-control | no-preview |
| go-import | github.com/realpython/realpython-blog git https://github.com/realpython/realpython-blog.git |
| octolytics-dimension-user_id | 5448020 |
| octolytics-dimension-user_login | realpython |
| octolytics-dimension-repository_id | 37278523 |
| octolytics-dimension-repository_nwo | realpython/realpython-blog |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 37278523 |
| octolytics-dimension-repository_network_root_nwo | realpython/realpython-blog |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 51c736e60b302bd039c9d5164573d176ceb24bb2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width