[Answer]-How do i define fields when creating an object?

1👍

Django requires your phone field to not be null right now. This also means you can’t pass phone=None, so if your phone variable that you’re passing into your Order object is None, it will fail.

Your options are:

  1. Set a default value on the model
  2. Allow null on the model
  3. Pass in a non-null value to the model upon creation
👤Jordan

0👍

Assuming from your question the model requires that phone number be there on creation.

Things you can do.

  1. phone_number = models.PhoneField(null=True, blank=True)
  2. phone_number = models.PhoneField(default='6132760547')

Those to model changes should help first is saying that the field can be blank as in contain an empty or None

Second is if nothing is passed default value is that number.

Leave a comment