[Answer]-Django generic view update/create: update works but create raises IntegrityError

1👍

Well, you have to set your required fields somewhere. If you don’t want them to be shown or editable in the form, your options are to set them in the view (by using a custom subclass of CreateView) or if appropriate to your design in the save method of the model class. Or declare an appropriate default value on the field in the model.

It would also work to allow the fields into the form, but set them to use HiddenInput widgets. That’s not safe against malicious input, so I wouldn’t do that for purely automated fields.

0👍

You cannot exclude fields, which are set as required in the model definition. You need to define blank=True/null=True for each of these model fields.

If this doesn’t solve your issue, then please show us the model and form definitions, so we know exactly what the code looks like.

Leave a comment