[Fixed]-IntegrityError at /admin/main/category/add/ NOT NULL constraint failed: main_category.author_id

1👍

Exception Value: NOT NULL constraint failed: main_category.author_id

You forgot to set the author via the admin:

class CatAdmin(admin.ModelAdmin): 

    prepopulated_fields = {'slug':('name',)}
    fields = ['name', 'slug', 'author']
    #                       ^^^^^^^^^^

Depending on your needs, you might want to make the author field optional:

class Category(models.Model): 
    ...
    # remove unique=True, add null=True
    author = models.OneToOneField(settings.AUTH_USER_MODEL, null=True)
    #                                                       ^^^^^^^^^
    ...

By the way, note that with a non-null OneToOneField, specifying unique=True is superfluous.

Leave a comment