class Sample(models.model):
sampleID = models.AutoField(primary_key=True)
something = models.IntegerField()
.
.
.
def save(self, *args, **kwargs):
is_new = self.pk is None
super(Sample, self).save(*args, **kwargs)
if is_new:
alpha = AnotherSample()
alpha.asampleID = self.pk
alpha.say = "Lolz"
alpha.save()
我无法将我的主键分配给 AnotherSample 的 Sample 引用键。它总是说
Cannot assign "1L": "AnotherSample.asampleID" must be a "Sample" instance.