[Fixed]-Set model field of child class as primary_key in Django

1👍

I hope this helps.

class ChildClass(AbstractClass):
    pass
ChildClass._meta.get_field('filename_base').blank = False
ChildClass._meta.get_field('filename_base').null = False
ChildClass._meta.get_field('filename_base').primary_key = True

And Primary key should be blank=False and null=False.

Note: in AbstractClass id already has primary key my answer is for NameError.

Leave a comment