1

I got this error after changing the engine, the database is connected however it figured out my id field is a bigint, yet I specifically set it as a UUID field.

class Cart(models.Model):
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
created_at = models.DateTimeField(auto_now_add=True)

in terminal I get this error:

django.db.utils.ProgrammingError: cannot cast type bigint to uuid
LINE 1: ...LE "store_cart" ALTER COLUMN "id" TYPE uuid USING "id"::uuid

enter image description here

  • You probably need to delete the initial migration, drop the table, and run migrations with UUID on the id column, as it seems that you can't case an integer to UUID. See https://stackoverflow.com/questions/20342717/postgresql-change-column-type-from-int-to-uuid – babis21 Aug 11 '22 at 12:59
  • My question would be why change it in the first place? – Adrian Klaver Aug 11 '22 at 15:04

1 Answers1

0

I was the same issues as you, And I fixed it by deleting all previous migrations tables, I hope it will work also for you.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 17 '22 at 19:45
  • this solution might get cause another error when you try to post or insert a new entry – Azhar Uddin Sheikh Aug 18 '23 at 06:44