【发布时间】:2020-08-29 15:39:47
【问题描述】:
我正在尝试 Django 文档中的 Django。
我在我的投票应用程序的 models.py 中创建了两个类:Publication 和 Articles,具有多对多字段:
class Article(models.Model):
publications=models.ManyToMany(Publication, ...)
然后在python shell中,我导入了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...
【问题讨论】:
-
请分享查询
-
@Gabip OP 没有直接运行查询,它是由
a1.publications.add(p1)行生成的。
标签: python django django-models many-to-many django-3.0