skip to Main Content

I have a problem with my Django database. When I enter: python manage.py makemigrations. I got this exception: AttributeError: module 'django.db.models' has no attribute 'PointField'. Here is my very simple code that cause the issue:

from django.db import models
import uuid

# Create your models here.
class Image(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4,editable=False)
    location = models.PointField()  # The culprit
    date = models.DateTimeField()
    image = models.ImageField()

Thank you in advance.

It supposed to make changes to my PostgreSQL database. Well the database hasn’t been made yet, I already initialize it with SQLite WITHOUT THE CODE ABOVE. IT WAS INITIALIZED BEFORE THERE IS ANYTHING IN THE MODELS FILES, trying to switch to PostgreSQL.

2

Answers


  1. Chosen as BEST ANSWER

    Fixed it, I need to import from django.contrib.gis.db.models import PointField and change the field to location = PointField()


  2. It is what error says. Even you pointed out. django.db.models does not have anything named PointField. So check this link from django docs and Select proper field type for your data.
    https://docs.djangoproject.com/en/5.0/ref/models/fields/

    best of luck

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search