Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.4K
Views
No se puede convertir el tipo entero a uuid

Intenté ejecutar python3 manage.py migrate , pero recibí este error :

 File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django /db/backends/utils.py", line 84, in _execute return self.cursor.execute(sql, params) django.db.utils.ProgrammingError: cannot cast type integer to uuid LINE 1: ...BLE "core_post" ALTER COLUMN "id" TYPE uuid USING "id"::uuid

Estoy usando PostgreSQL

Mis modelos.py: Enlace a pastebin

Espero que me ayudes)

¡Gracias!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Entonces, básicamente comenzaste el modelo sin una clave primaria explícita. Así que obtuviste un AutoField gratuito y ahora quieres que sean UUID.

Como puede ver, Postgres (o cualquier base de datos que conozca) no permite cambiar números enteros a UUID. Por lo tanto, debe realizar algunas migraciones para obtener el estado que desea:

Primero agregue el campo uuid como un campo normal con un nombre diferente:

 import uuid from django.db import models class MyModel(models.Model): uuid = models.UUIDField(default=uuid.uuid4, unique=True)

Ejecute makemigrations y migre.

Ahora hazlo clave principal:

 class MyModel(models.Model): uuid = models.UUIDField(default=uuid.uuid4, primary_key=True)

Esto debería generar una migración que elimine el campo de identificación y haga que la clave principal sea uuid (hacer migraciones y migrar nuevamente).

Y finalmente (si todavía quieres):

 class MyModel(models.Model): id = models.UUIDField(default=uuid.uuid4, primary_key=True)

Honestamente, no sé si esto va bien, es posible que deba ajustar la migración generada. En cualquier caso, ahora deberías estar donde quieres estar.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!