psycopg2. errors.SyntaxError: "ON "处或附近的语法错误。

问题描述 投票:-1回答:1

我正在尝试Django文档中的Django.我在我的投票应用上创建了两个类models.py。PublicationArticles,有一个多对多的领域。

class Article(models.Model):
    publications=models.ManyToMany(Publication, ...)

那么在 蟒蛇壳我导入了Ran。

>>> from polls.models import Publication,Articles
>>> p1=Publication.objects.get(id=1)
>>> p2=Publication.objects.get(id=2)
>>> p3=Publication.objects.get(id=3)
>>> a1=Articles(headlines="When will be the lockdown get finished?")
>>> a1.publications.add(p1) 

我得到一个错误。

Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.SyntaxError: syntax error at or near "ON"
LINE 1: ..." ("articles_id", "publication_id") VALUES (2, 1) ON CONFLIC...
python django django-models many-to-many
1个回答
1
投票

Django 3.0支持PostgreSQL 9.5及以上版本。. 你出现这个错误是因为你使用的PostgreSQL的早期版本不支持 ON CONFLICT.

要解决这个问题,你可以升级PostgreSQL,或者降级到最新的Django 2.2.X,后者支持PostgreSQL 9.4及以上版本。

© www.soinside.com 2019 - 2024. All rights reserved.