[Fixed]-Django OneToOneField default value

12👍

As NOT NULL constraint is getting failed hence error.

Either make null=True

album = models.OneToOneField(Album,on_delete=models.CASCADE, null=True)

Or use signals to connect the user with the album.

1👍

Since:

1) all the fields on album are nullable or have default values and

2) you can pass a callable to the default arg

This should work:

album = models.OneToOneField(Album, on_delete=models.CASCADE, default=Album.objects.create)

Leave a comment