【问题标题】:How do I use the existing tables in Postgres DB and use them in Django如何使用 Postgres DB 中的现有表并在 Django 中使用它们
【发布时间】:2020-08-20 10:23:09
【问题描述】:

我是 Django 新手,我正在尝试为可以查看、插入/更新/删除数据到 PostgreSQL 数据库的用户构建一个 Web 控制台。

我已经创建了几个要使用的表。我使用下面的命令来检查表并在 Django 模型中使用它们

$ python manage.py inspectdb bkp_fulfilment_product_provider > models.py

当我运行上述命令时,我收到如下错误: 版本:

PostgresSql 版本 9.2.18 和 Django 版本 3.1 错误:

# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
#   * Rearrange models' order
#   * Make sure each model has one field with primary_key=True
#   * Make sure each `ForeignKey` and `OneToOneField` has `on_delete` set to the desired behaviour
#   * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
    from `django.db` import models
# Unable to inspect table bkp_fulfilment_product_provider
# The error was: syntax error at or near `WITH ORDINALITY`
LINE 6:                        FROM `unnest(c.conkey)` WITH ORDINALITY co...

【问题讨论】:

  • 您使用的 postgres 和 django 版本是什么,以及创建特定表的 sql
  • PostgresSql 版本 9.2.18 和 Django 版本 3.1。表已经存在于数据库中,CREATE TABLE bkp_fulfilment_product_provider (product_code varchar(100) NULL, fulfilment_provider_code varchar(100) NULL, is_primary bool NULL, on_hand_stock int4 NULL, on_order_stock int4 NULL);
  • 您尝试使用的 Django 版本不支持您的 PostgreSQL 版本docs.djangoproject.com/en/3.1/ref/databases/#postgresql-notes 您应该更新 PostgreSQL
  • 感谢 iklinac,我认为我们无法升级数据库。你还有什么建议。我的目的是让我自己动手使用 python 并为用户构建一个 Web 界面
  • 正如我已经说过的,您可以使用旧版本,但 postgre 和 django 版本都被认为是旧版本,仍然会建议更新数据库

标签: python django postgresql


【解决方案1】:

您的 PostgreSQL 次要版本已经 4 年了,并且 PostgreSQL 已经 3 年没有 fix supported 了

支持此数据库版本的最新 Django 版本是 1.10,它被认为是不安全的

你应该更新你的 PostgreSQL 到新版本

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-30
    • 2022-07-14
    • 1970-01-01
    • 2022-07-07
    • 2022-12-03
    • 2014-10-16
    • 1970-01-01
    相关资源
    最近更新 更多