需要帮助的人,表gigpost_category没有标题为标题的列

问题描述 投票:0回答:1

我正在尝试制作一个简单的博客,而我正面临这个问题。因此,当我尝试在管理面板中添加模型时,会显示此错误?这是代码

models.py

from django.db import models
from django.utils import timezone
from django.conf import settings

# Create your models here.
class Category(models.Model):
    titled=models.CharField(max_length=100,default='')

    def __str__(self):
        return self.title
class Gigpost(models.Model):

    title=models.CharField(default='',max_length=100,blank=False)
    user=models.OneToOneField(settings.AUTH_USER_MODEL,on_delete=models.CASCADE,blank=False)
    categories=models.OneToOneField(Category,on_delete=models.PROTECT,default='',blank=False)
    published_at=models.DateTimeField(auto_now_add=True)
    description=models.TextField(default='',max_length=None,blank=False)
    mainphoto=models.ImageField(default='')
    photo=models.ImageField()
    def __str__(self):
        return self.title


class Comment_area(models.Model):

    user=models.OneToOneField(settings.AUTH_USER_MODEL,on_delete=models.CASCADE,blank=False)
    comment=models.TextField(max_length=None,default='')
    commented_at=models.DateTimeField(auto_now_add=True)

admin.py

from django.contrib import admin
from .models import Gigpost , Category

# Register your models here.
admin.site.register(Gigpost)
admin.site.register(Category)

错误消息:

OperationalError at /admin/gigpost/category/add/
table gigpost_category has no column named titled
Request Method: POST
Request URL:    http://127.0.0.1:8000/admin/gigpost/category/add/
Django Version: 2.2.5
Exception Type: OperationalError
Exception Value:    
table gigpost_category has no column named titled

感谢帮助天才的人:D

django django-models
1个回答
0
投票

修正了您的错字等,请尝试以下操作:

models.py

from django.db import models
from django.utils import timezone
from django.conf import settings
from django.contrib.auth.models import User

# Create your models here.
class Category(models.Model):
    title = models.CharField(max_length=100, default='')

    def __str__(self):
        return self.title

class Gigpost(models.Model):

    title = models.CharField(default='',max_length=100)
    user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
    categorie=models.ForeignKey(Category,on_delete=models.SET_NULL, null=True)
    published_at = models.DateTimeField(auto_now_add=True)
    description = models.TextField(default='')
    mainphoto = models.ImageField(blank=True)
    photo = models.ImageField(blank=True)

    def __str__(self):
        return self.title


class Comment_area(models.Model):

    user=models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
    comment=models.TextField(default='')
    commented_at=models.DateTimeField(auto_now_add=True)
© www.soinside.com 2019 - 2024. All rights reserved.