'ERROR: (models.E015) 'ordering' refers to the nonexistent field, related field, or lookup 'name'
I simply can't understand why I get this error:
(models.E015) 'ordering' refers to the nonexistent field, related field, or lookup 'name'
from django.db import models
class Category(models.Model):
name = models.CharField(max_length=255),
slug = models.SlugField()
class Meta:
ordering = ('name',)
def __str__(self):
return self.name
def get_absolute_url(self):
return f'/{self.slug}'
Solution 1:[1]
Ah, I guess it is the comma at the end of the name field declaration...
Solution 2:[2]
Remove the comma and have it this way:
class Meta:
ordering = ('name')
Then run the makemigrations && migrate commands.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | peter-sari |
| Solution 2 | ouflak |
