gpt4 book ai didi

python - 如何解决Django中的 "OperationalError: no such column"?

转载 作者:行者123 更新时间:2023-12-04 12:45:56 24 4
gpt4 key购买 nike

我正在为电子商务网站制作一个购物车应用程序来处理用户 session 。单击购物车部分时,我在管理页面中收到此错误:

OperationalError at /admin/carts/cart/ no such column: carts_cart.user_id
Request Method: GET
Request URL: 127.0.0.1:8000/admin/carts/cart

这是购物车模型:

from django.db import models
from django.conf import settings
from django.urls import reverse
from products.models import product

user=settings.AUTH_USER_MODEL

class cart(models.Model):
user = models.ForeignKey(user, null=True, blank=True)
products = models.ManyToManyField(product, blank=True)
total = models.DecimalField(default=0.00, max_digits=100, decimal_places=2)
updated = models.DateTimeField(auto_now=True)
timestamp = models.DateTimeField(auto_now_add=True)

def __str__(self):
return str(self.id)

def __unicode__(self):
return str(self.id)

View .py

from django.shortcuts import render
from .models import cart

def cart_home(request):
return render(request,"carts/home.html",{})

设置.py

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
#ourapps

'products',
'search',
'carts',
'tags',
]

产品、搜索、标签工作正常

最佳答案

我简单地转到我的项目目录并手动删除了 dbsqlite 文件。之后,我重新运行...

python manage.py makemigrations

python manage.py migrate

一切顺利

关于python - 如何解决Django中的 "OperationalError: no such column"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48438100/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com