我正在从Django文档中尝试Django。
我在轮询应用程序的models.py中创建了两个类:Publication
和Articles
,其中包含多对多字段:
class Article(models.Model):
publications=models.ManyToMany(Publication, ...)
然后在pythonshell中,我导入了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...
Django 3.0 supports PostgreSQL 9.5 and higher。出现此错误是因为您使用的是不支持
ON CONFLICT
的早期版本的PostgreSQL要解决这个问题,您可以升级PostgreSQL,也可以降级到最新的Django 2.2.X,它支持PostgreSQL 9.4及更高版本
相关问题 更多 >
编程相关推荐