0

I have a schema that goes like the following

class Order(models.Model):
    order_id = models.AutoField(max_length=120,primary_key=True)
    timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
    delivery_address = models.CharField(max_length=200, blank=True)
    order_Desc= ArrayField(JSONField(),default=list, null=True);
    order_by = models.ForeignKey(User,null=True, blank=True,on_delete=models.CASCADE);

I was initially trying to set a list of JSON objects into the order description columns but was constantly facing an issue column "order_Desc" is of type jsonb[] but expression is of type text[] while model object create. So I tried to convert order_Desc= ArrayField(JSONField(),default=list, null=True); to order_Desc= JSONField(blank =True,null=True) but I get the following error while migrating

django.db.utils.ProgrammingError: cannot cast type jsonb[] to jsonb
LINE 1: ...TER COLUMN "order_Desc" TYPE jsonb USING "order_Desc"::jsonb

I am not sure what to do. I tried reverting back to the old state but somehow I still get the same issue which was weird. I also tried adding a new column to the model of type JSONField keeping the old state as it was but this error never seem to go. Thank for your help in advance.

1 Answer 1

1

If you get an error while migrating it means that the migration did not pass, and so you don't need to revert it; just remove the generated migration file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.