Humza Din
Humza Din

Reputation: 71

Django: NOT NULL constraint failed: new__create_post.author_id

Error: NOT NULL constraint failed: new__create_post.author_id

models:

class Post(models.Model):

    author = models.ForeignKey(User, on_delete=models.CASCADE, default=None)
    

Upvotes: 0

Views: 138

Answers (1)

Mohammed Abdelawel
Mohammed Abdelawel

Reputation: 113

you can't do this default=None because your field don't accept null values by default try to make field like this :

author = models.ForeignKey(User, on_delete=models.CASCADE, default=None, null=True, blank=True)

it should work ... but you need to delete last migrations file like the pic enter image description here

Upvotes: 2

Related Questions