小编Mur*_*dam的帖子

如何从 Postgres 转储中 pg_restore 一张表及其架构?

我在恢复表的架构时遇到一些困难。我转储了 Heroku Postgres 数据库,并使用 pg_restore 将其中一张表恢复到我的本地数据库(它有 20 多个表)。它已成功恢复,但当我尝试将新数据插入表中时遇到问题。

当我使用psql打开数据库时,我发现恢复的表包含所有数据,但其架构有零行。无论如何,我可以从转储中导入表及其架构吗?非常感谢。

这就是我将表恢复到本地数据库的方法:

pg_restore -U postgres --dbname my_db --table=message latest.dump
Run Code Online (Sandbox Code Playgroud)

编辑:

我按照官方文档尝试了类似的操作,但它被阻止了,什么也没有发生。我的数据库很小,不超过几兆字节,并且我尝试恢复的表架构不超过 100 行。

pg_restore -U postgres --dbname mydb --table=message --schema=message_id_seq latest.dump
Run Code Online (Sandbox Code Playgroud)

postgresql pg-dump heroku pg-restore heroku-postgres

7
推荐指数
1
解决办法
3万
查看次数

Python:如何计算文件中的数字总和?

如何计算.txt文件中的数字总和文件中的数据格式为:

7
8
14
18
16
8
23
...
Run Code Online (Sandbox Code Playgroud)

我从文件中读取数据并将每个行值分配给'line'可变,但我希望得到类似的东西: result = 7+8+14+...

f = open('data.txt', 'r')   #LOOP AND READ DATA FROM THE FILE
    for line in f:
        code
Run Code Online (Sandbox Code Playgroud)

python arrays file calculation

3
推荐指数
1
解决办法
1375
查看次数

预提交 isort 没有名为“setuptools”的模块

我正在尝试运行预提交挂钩,但是当它们遇到 isort 挂钩时会失败,该挂钩会引发以下错误:

  File "/home/el/.cache/pre-commit/repoffrjhcx0/py_env-python3/lib/python3.10/site-packages/_distutils_hack/__init__.py", line 92, in create_module
    return importlib.import_module('setuptools._distutils')
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'setuptools'
Run Code Online (Sandbox Code Playgroud)

我正在使用 docker,并且我已经检查了 setuptools 是否已安装在我的全局计算机和 docker 上。我不明白为什么会出现这个错误。我认为 isort 设置了它自己的环境,但是为什么它不会被安装,因为它是在配置文件pyproject.toml中定义的。

以下是我的预提交和 isort 配置:

.pre-commit-config.yaml

repos:
- repo: https://github.com/pycqa/isort
  rev: 5.8.0
  hooks:
    - id: isort
      args: ["--multi-line=5", "--line-length=120", "--use-parentheses", "--filter-files"]
      exclude: "migrations"
      stages: [commit]
Run Code Online (Sandbox Code Playgroud)

毒物文件

[isort]
line_length=120
skip_glob=*migrations*
multi_line_output=5
sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
use_parentheses=true
include_trailing_comma=true
lines_between_types=1
lines_after_imports=2
[testenv:isort]
deps =
    isort
commands =
    isort . --check-only --diff
Run Code Online (Sandbox Code Playgroud)

系统上的Python版本:3.10.1 …

python pre-commit pre-commit-hook isort pre-commit.com

3
推荐指数
1
解决办法
1508
查看次数

Postgresql 顺序乱序

我有一个数据库,我需要按照表中填充的顺序检索数据。表名是 bible 当我在 psql 中输入时table bible;,它会按照填充的顺序打印数据,但是当我尝试检索它时,某些行总是乱序,如下例所示:

table bible

-[ RECORD 1 ]-----------------------------------------------------------------------------------------------------------------------------------------
id      | 1
day     | 1
book    | Genesis
chapter | 1
verse   | 1
text    | In the beginning God created the heavens and the earth.
link    | https://api.biblia.com/v1/bible/content/asv.txt.txt?passage=Genesis1.1&key=dc5e2d416f46150bf6ceb21d884b644f
-[ RECORD 2 ]-----------------------------------------------------------------------------------------------------------------------------------------
id      | 2
day     | 1
book    | John
chapter | 1
verse   | 1
text    | In the beginning was the Word, and the Word was with God, and the Word …
Run Code Online (Sandbox Code Playgroud)

sql database django postgresql psql

2
推荐指数
1
解决办法
952
查看次数

coverage.misc.NoSource:没有代码源:'/usr/src/server/rep-1>'

我现在使用覆盖包已经有一段时间了,它运行良好,直到昨天,它只是在生成我认为的报告的水平上失败了。功能上没有任何变化,但更奇怪的是。

我有以下coveragerc文件:

[run]
source = .
branch = True
concurrency = multiprocessing
omit =
    manage.py
    config/asgi.py
    config/wsgi.py
    config/settings.py
    */migrations/*
    *test*

[report]
show_missing = True
skip_covered = True
Run Code Online (Sandbox Code Playgroud)

Django的manage.py文件如下:

import os
import sys


COVERAGE_ACCCEPTANCE = 85


def main():
    argv = sys.argv
    try:
        command = argv[1]
    except IndexError:
        command = "help"
    default_settings = "config.settings"
    running_tests = (command == "test")
    if running_tests:
        default_settings = "config.settings_test"
        from coverage import Coverage
        cov = Coverage()
        cov.erase()
        cov.start()
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", default_settings)
    try:
        from django.core.management import execute_from_command_line …
Run Code Online (Sandbox Code Playgroud)

python django coverage.py gitlab-pipelines

2
推荐指数
1
解决办法
1157
查看次数