小编Mik*_*ton的帖子

如何从 django 模型中获取 Id

嗨,我有两个名为 A 和 B 的模型。我想从模型 B 中获取 ID,并将其与模型 A(外键关系)中的 ID 进行比较。我使用以下方法来获取ID a = B.objects.filter(b_id=object.id).values_list('id')

但是打印的结果是[(82L,), (83L,), (84L,), (85L,)]而不是[82, 83 ,]等。如何在没有附加Ls 的情况下获得平面列表?

python django django-views django-filter

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

Django 1.8错误:未指定数据库装置

我使用的是sqlite数据库,应用后python manage.py dumpdata我在中添加了新的postgresql数据库设置settings.py

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'music',                      
    'USER': '**',
    'PASSWORD': '****',
    'HOST': '127.0.0.1',
    'PORT': '5432',
    }
  }
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试将数据加载到新postgresql数据库中时,出现以下错误

C:\Users\Saket\musicalguru>python manage.py loaddata
usage: manage.py loaddata [-h] [--version] [-v {0,1,2,3}]
                      [--settings SETTINGS] [--pythonpath PYTHONPATH]
                      [--traceback] [--no-color] [--database DATABASE]
                      [--app APP_LABEL] [--ignorenonexistent]
                      fixture [fixture ...]
manage.py loaddata: error: No database fixture specified. Please provide the  path of at least one fixture in the command line.
Run Code Online (Sandbox Code Playgroud)

无法理解错误是什么。我的sqlite数据库中已经有数据,所以我也需要数据库中的新数据postgresql …

python django postgresql django-database

0
推荐指数
1
解决办法
6218
查看次数