class Article (models.Model):
id=models.BigAutoField(primary_key=True)
title=models.CharField(max_length=32)
publishtime=models.DateTimeField(auto_now_add=True)
catalogs=models.ForeignKey(to="Catalog")
tags=models.ManyToManyField("Tag")
-sharp content=models.OneToOneField(to="ArticleContent")
content=models.TextField()
Test program
catalogs=models.Catalog.objects.all ()
tags=models.Tag.objects.all ()
c=random.choice (catalogs)
t=random.choice (tags)
models.Article.objects.create (title="article"+str (i), catalogs=c,tags=t,content=str (i))
error
ValueError: "< Article: article4 >" needs to have a value for field "id" before this many-to-many relationship can be used.
indicates that
id is self-increasing in the database, but the display definition is used when setting up the model. When bigauto, causes data to be added, it is also displayed that the specified id, does not want to be specified, but wants to add itself through the database.