- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在提交凭据后尝试登录时,我部署的 Web 应用程序在生产环境中立即崩溃。
通常,我必须运行:
heroku run python manage.py migrate
更新 Heroku 数据库中的更改,但是当我这样做时,请在下面找到发生了什么。
这是终端返回的内容。
Running python manage.py migrate on ⬢ friendsbook-demo... up, run.1779 (Hobby)
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
self.connect()
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/base/base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/postgresql/base.py", line 168, in get_new_connection
connection = Database.connect(**conn_params)
File "/app/.heroku/python/lib/python3.7/site-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 79, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/migrations/loader.py", line 206, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/migrations/recorder.py", line 61, in applied_migrations
if self.has_table():
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/migrations/recorder.py", line 44, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/base/base.py", line 255, in cursor
return self._cursor()
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/base/base.py", line 232, in _cursor
self.ensure_connection()
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
self.connect()
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
self.connect()
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/base/base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/postgresql/base.py", line 168, in get_new_connection
connection = Database.connect(**conn_params)
File "/app/.heroku/python/lib/python3.7/site-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
我在 Stack Overflow 上看到了一些关于检查 Postgres 是否正在运行的代码,并尝试了其中一些,但它们不起作用。
这是我运行 heroku logs -t
时发生的情况:
2019-04-23T02:27:22.203770+00:00 app[web.1]: Traceback (most recent call last):
2019-04-23T02:27:22.203772+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 475, in parse
2019-04-23T02:27:22.203773+00:00 app[web.1]: compile_func = self.tags[command]
2019-04-23T02:27:22.203775+00:00 app[web.1]: KeyError: 'static'
2019-04-23T02:27:22.203776+00:00 app[web.1]:
2019-04-23T02:27:22.203778+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2019-04-23T02:27:22.203779+00:00 app[web.1]:
2019-04-23T02:27:22.203781+00:00 app[web.1]: Traceback (most recent call last):
2019-04-23T02:27:22.203782+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/exception.py", line 35, in inner
2019-04-23T02:27:22.203784+00:00 app[web.1]: response = get_response(request)
2019-04-23T02:27:22.203785+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/whitenoise/middleware.py", line 49, in __call__
2019-04-23T02:27:22.203787+00:00 app[web.1]: response = self.get_response(request)
2019-04-23T02:27:22.203789+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/exception.py", line 37, in inner
2019-04-23T02:27:22.203790+00:00 app[web.1]: response = response_for_exception(request, exc)
2019-04-23T02:27:22.203792+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/exception.py", line 87, in response_for_exception
2019-04-23T02:27:22.203794+00:00 app[web.1]: response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
2019-04-23T02:27:22.203796+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/exception.py", line 126, in handle_uncaught_exception
2019-04-23T02:27:22.203797+00:00 app[web.1]: return callback(request, **param_dict)
2019-04-23T02:27:22.203798+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
2019-04-23T02:27:22.203800+00:00 app[web.1]: response = view_func(request, *args, **kwargs)
2019-04-23T02:27:22.203801+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/views/defaults.py", line 69, in server_error
2019-04-23T02:27:22.203803+00:00 app[web.1]: template = loader.get_template(template_name)
2019-04-23T02:27:22.203812+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/loader.py", line 15, in get_template
2019-04-23T02:27:22.203814+00:00 app[web.1]: return engine.get_template(template_name)
2019-04-23T02:27:22.203816+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/backends/django.py", line 34, in get_template
2019-04-23T02:27:22.203817+00:00 app[web.1]: return Template(self.engine.get_template(template_name), self)
2019-04-23T02:27:22.203819+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/engine.py", line 144, in get_template
2019-04-23T02:27:22.203821+00:00 app[web.1]: template, origin = self.find_template(template_name)
2019-04-23T02:27:22.203822+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/engine.py", line 126, in find_template
2019-04-23T02:27:22.203824+00:00 app[web.1]: template = loader.get_template(name, skip=skip)
2019-04-23T02:27:22.203825+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/loaders/cached.py", line 55, in get_template
2019-04-23T02:27:22.203827+00:00 app[web.1]: template = super().get_template(template_name, skip)
2019-04-23T02:27:22.203829+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/loaders/base.py", line 30, in get_template
2019-04-23T02:27:22.203832+00:00 app[web.1]: contents, origin, origin.template_name, self.engine,
2019-04-23T02:27:22.203833+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 160, in __init__
2019-04-23T02:27:22.203834+00:00 app[web.1]: self.nodelist = self.compile_nodelist()
2019-04-23T02:27:22.203835+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 198, in compile_nodelist
2019-04-23T02:27:22.203836+00:00 app[web.1]: return parser.parse()
2019-04-23T02:27:22.203837+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 477, in parse
2019-04-23T02:27:22.203839+00:00 app[web.1]: self.invalid_block_tag(token, command, parse_until)
2019-04-23T02:27:22.203840+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 539, in invalid_block_tag
2019-04-23T02:27:22.203841+00:00 app[web.1]: "or load this tag?" % (token.lineno, command)
2019-04-23T02:27:22.203842+00:00 app[web.1]: django.template.exceptions.TemplateSyntaxError: Invalid block tag on line 10: 'static'. Did you forget to register or load this tag?
2019-04-23T02:27:22.203844+00:00 app[web.1]:
2019-04-23T02:27:22.203845+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2019-04-23T02:27:22.203846+00:00 app[web.1]:
2019-04-23T02:27:22.203847+00:00 app[web.1]: Traceback (most recent call last):
2019-04-23T02:27:22.203848+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 475, in parse
2019-04-23T02:27:22.203849+00:00 app[web.1]: compile_func = self.tags[command]
2019-04-23T02:27:22.203850+00:00 app[web.1]: KeyError: 'static'
2019-04-23T02:27:22.203851+00:00 app[web.1]:
2019-04-23T02:27:22.203852+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2019-04-23T02:27:22.203853+00:00 app[web.1]:
2019-04-23T02:27:22.203854+00:00 app[web.1]: Traceback (most recent call last):
2019-04-23T02:27:22.203855+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/sync.py", line 135, in handle
2019-04-23T02:27:22.203857+00:00 app[web.1]: self.handle_request(listener, req, client, addr)
2019-04-23T02:27:22.203858+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/sync.py", line 176, in handle_request
2019-04-23T02:27:22.203864+00:00 app[web.1]: respiter = self.wsgi(environ, resp.start_response)
2019-04-23T02:27:22.203865+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/wsgi.py", line 146, in __call__
2019-04-23T02:27:22.203866+00:00 app[web.1]: response = self.get_response(request)
2019-04-23T02:27:22.203867+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/base.py", line 81, in get_response
2019-04-23T02:27:22.203868+00:00 app[web.1]: response = self._middleware_chain(request)
2019-04-23T02:27:22.203869+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/exception.py", line 37, in inner
2019-04-23T02:27:22.203870+00:00 app[web.1]: response = response_for_exception(request, exc)
2019-04-23T02:27:22.203875+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/exception.py", line 87, in response_for_exception
2019-04-23T02:27:22.203876+00:00 app[web.1]: response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
2019-04-23T02:27:22.203877+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/exception.py", line 126, in handle_uncaught_exception
2019-04-23T02:27:22.203878+00:00 app[web.1]: return callback(request, **param_dict)
2019-04-23T02:27:22.203879+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
2019-04-23T02:27:22.203880+00:00 app[web.1]: response = view_func(request, *args, **kwargs)
2019-04-23T02:27:22.203881+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/views/defaults.py", line 69, in server_error
2019-04-23T02:27:22.203882+00:00 app[web.1]: template = loader.get_template(template_name)
2019-04-23T02:27:22.203883+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/loader.py", line 15, in get_template
2019-04-23T02:27:22.203884+00:00 app[web.1]: return engine.get_template(template_name)
2019-04-23T02:27:22.203886+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/backends/django.py", line 34, in get_template
2019-04-23T02:27:22.203887+00:00 app[web.1]: return Template(self.engine.get_template(template_name), self)
2019-04-23T02:27:22.203888+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/engine.py", line 144, in get_template
2019-04-23T02:27:22.203889+00:00 app[web.1]: template, origin = self.find_template(template_name)
2019-04-23T02:27:22.203890+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/engine.py", line 126, in find_template
2019-04-23T02:27:22.203892+00:00 app[web.1]: template = loader.get_template(name, skip=skip)
2019-04-23T02:27:22.203893+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/loaders/cached.py", line 55, in get_template
2019-04-23T02:27:22.203894+00:00 app[web.1]: template = super().get_template(template_name, skip)
2019-04-23T02:27:22.203896+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/loaders/base.py", line 30, in get_template
2019-04-23T02:27:22.203897+00:00 app[web.1]: contents, origin, origin.template_name, self.engine,
2019-04-23T02:27:22.203898+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 160, in __init__
2019-04-23T02:27:22.203899+00:00 app[web.1]: self.nodelist = self.compile_nodelist()
2019-04-23T02:27:22.203900+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 198, in compile_nodelist
2019-04-23T02:27:22.203901+00:00 app[web.1]: return parser.parse()
2019-04-23T02:27:22.203902+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 477, in parse
2019-04-23T02:27:22.203903+00:00 app[web.1]: self.invalid_block_tag(token, command, parse_until)
2019-04-23T02:27:22.203905+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/template/base.py", line 539, in invalid_block_tag
2019-04-23T02:27:22.203906+00:00 app[web.1]: "or load this tag?" % (token.lineno, command)
2019-04-23T02:27:22.203907+00:00 app[web.1]: django.template.exceptions.TemplateSyntaxError: Invalid block tag on line 10: 'static'. Did you forget to register or load this tag?
2019-04-23T02:27:22.203908+00:00 app[web.1]: 10.65.34.10 - - [22/Apr/2019:22:27:22 -0400] "POST /login/ HTTP/1.1" 500 0 "-" "-"
2019-04-23T02:33:48.861658+00:00 app[api]: Starting process with command `python manage.py migrate` by user accelcapital18@gmail.com
2019-04-23T02:33:54.228660+00:00 heroku[run.1779]: Awaiting client
2019-04-23T02:33:54.274166+00:00 heroku[run.1779]: Starting process with command `python manage.py migrate`
2019-04-23T02:33:54.532907+00:00 heroku[run.1779]: State changed from starting to up
2019-04-23T02:33:58.977205+00:00 heroku[run.1779]: State changed from up to complete
2019-04-23T02:33:58.954246+00:00 heroku[run.1779]: Process exited with status 1
这是什么原因造成的,我该如何解决?
最佳答案
您正在尝试连接到 127.0.0.1
上的数据库,但 Heroku 的 Postgres 服务不会以这种方式运行。您的数据库不会与您的应用程序代码位于同一台机器上。
Heroku 将通过 DATABASE_URL
环境变量提供您的数据库凭据。有几种不同的方法可以使用它,但这里有一些流行的方法:
使用 dj-database-url
,例如通过将它添加到您的应用程序依赖项,然后在您的 settings.py
中执行类似的操作:
import dj_database_url
DATABASES['default'] = dj_database_url.config(default='postgres://...')
这告诉 Django 使用 DATABASE_URL
中的值(如果存在),否则返回到提供的 default
值,例如在你的开发机器上。
使用 django-heroku
,由 Heroku 维护,它负责处理您的 DATABASE_URL
和 Heroku 推荐的其他一些事情。对于这个,将其添加为依赖项,然后将其添加到 settings.py
的底部:
import django_heroku
django_heroku.settings(locals())
关于python - 尝试迁移数据库时 Django 应用程序在 Heroku 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55809372/
我的问题是如何在 python 中创建一个简单的数据库。我的例子是: User = { 'Name' : {'Firstname', 'Lastname'}, 'Address' : {'Street
我需要创建一个与远程数据库链接的应用程序! mysql 是最好的解决方案吗? Sqlite 是唯一的本地解决方案吗? 我使用下面的方法,我想知道它是否是最好的方法! NSString *evento
给定两台 MySQL 服务器,一台本地,一台远程。两者都有一个包含表 bohica 的数据库 foobar。本地服务器定义了用户 'myadmin'@'%' 和 'myadmin'@'localhos
我有以下灵活的搜索查询 Select {vt:code},{vt:productcode},{vw:code},{vw:productcode} from {abcd AS vt JOIN wxyz
好吧,我的电脑开始运行有点缓慢,所以我重置了 Windows,保留了我的文件。因为我的大脑还没有打开,所以我忘记事先备份我的 MySQL 数据库。我仍然拥有所有原始文件,因此我实际上仍然拥有数据库,但
如何将我的 Access 数据库 (.accdb) 转换为 SQLite 数据库 (.sqlite)? 请,任何帮助将不胜感激。 最佳答案 1)如果要转换 db 的结构,则应使用任何 DB 建模工具:
系统检查发现了一些问题: 警告:?:(mysql.W002)未为数据库连接“默认”设置 MySQL 严格模式 提示:MySQL 的严格模式通过将警告升级为错误来修复 MySQL 中的许多数据完整性问题
系统检查发现了一些问题: 警告:?:(mysql.W002)未为数据库连接“默认”设置 MySQL 严格模式 提示:MySQL 的严格模式通过将警告升级为错误来修复 MySQL 中的许多数据完整性问题
我想在相同的 phonegap 应用程序中使用 android 数据库。 更多说明: 我创建了 phonegap 应用程序,但 phonegap 应用程序不支持服务,所以我们已经在 java 中为 a
Time Tracker function clock() { var mytime = new Date(); var seconds
我需要在现有项目上实现一些事件的显示。我无法更改数据库结构。 在我的 Controller 中,我(从 ajax 请求)传递了一个时间戳,并且我需要显示之前的 8 个事件。因此,如果时间戳是(转换后)
我有一个可以收集和显示各种测量值的产品(不会详细介绍)。正如人们所期望的那样,显示部分是一个数据库+建立在其之上的网站(使用 Symfony)。 但是,我们可能还会创建一个 API 来向第三方公开数据
我们将 SQL Server 从 Azure VM 迁移到 Azure SQL 数据库。 Azure VM 为 DS2_V2、2 核、7GB RAM、最大 6400 IOPS Azure SQL 数据
我正在开发一个使用 MongoDB 数据库的程序,但我想问在通过 Java 执行 SQL 时是否可以使用内部数据库进行测试,例如 H2? 最佳答案 你可以尝试使用Testcontainers Test
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 已关闭 9 年前。 此问题似乎与 a specific programming problem, a sof
我正在尝试使用 MSI 身份验证(无需用户名和密码)从 Azure 机器学习服务连接 Azure SQL 数据库。 我正在尝试在 Azure 机器学习服务上建立机器学习模型,目的是我需要数据,这就是我
我在我的 MySQL 数据库中使用这个查询来查找 my_column 不为空的所有行: SELECT * FROM my_table WHERE my_column != ""; 不幸的是,许多行在
我有那个基地:http://sqlfiddle.com/#!2/e5a24/2这是 WordPress 默认模式的简写。我已经删除了该示例不需要的字段。 如您所见,我的结果是“类别 1”的两倍。我喜欢
我有一张这样的 table : mysql> select * from users; +--------+----------+------------+-----------+ | userid
我有表: CREATE TABLE IF NOT EXISTS `category` ( `id` int(11) NOT NULL, `name` varchar(255) NOT NULL
我是一名优秀的程序员,十分优秀!