广告区

广告区


本站消息

站长简介/公众号

关注本站官方公众号:程序员总部,领取三大福利!
福利一:python和前端辅导
福利二:进程序员交流微信群,专属于程序员的圈子
福利三:领取全套零基础视频教程(python,java,前端,php)

  价值13000svip视频教程,python大神匠心打造,零基础python开发工程师视频教程全套,基础+进阶+项目实战,包含课件和源码

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

django 错误 1146 “表 'buysell.sell_sellform' 不存在”

发布于2022-05-21 12:15     阅读(313)     评论(0)     点赞(19)     收藏(1)



我正在尝试创建一个表单并将其数据存储在我创建模型的数据库中,但它也显示错误。模型.py

from django.db import models
from django.contrib.auth.models import User

class SellForm(models.Model):
    FICTION = 'fiction'
    Course = 'course'
    Non_Fiction = 'nonfic'
    book_category = [
        (FICTION, 'Fiction'),
        (Course, 'Course'),
        (Non_Fiction, 'Non fiction'),
    ]
    NEW = 'new'
    OLD = 'old'
    book_condition =[
        (NEW,'new'),
        (OLD, 'old'),
    ]
    ENGLISH = 'eng'
    HINDI = 'Hindi'
    book_lang =[
        (ENGLISH,'english'),
    (HINDI,'hindi'),
    ]

    title = models.CharField(max_length=100)
    author = models.CharField(max_length=100)
    price = models.IntegerField()
    Category = models.CharField(max_length=20,choices=book_category,default=Course,)
    Condition = models.CharField(max_length=20,choices=book_condition,default=OLD)
    Language = models.CharField(max_length=20,choices=book_lang,default=HINDI)
    Description =models.CharField(max_length=200)
    book_img = models.ImageField(upload_to='images/')
    user = models.ForeignKey(User, on_delete=models.CASCADE)

表格.py

from django import forms
from .models import SellForm

class FromSellForm(forms.ModelForm):
    class Meta:
        model = SellForm
        fields = ["title","author","price","Category","Condition","Language","Description","book_img"]

视图.py

from django.shortcuts import render,redirect
from django.http import HttpResponse
from .forms import FromSellForm

# Create your views here.
def sell_book(request):
    if request.method == 'POST':
        form = FromSellForm(request.POST,request.FILES)
        if form.is_valid():
            form.save()
            return redirect('home')
    else:
        form = FromSellForm()
    context = {'form':form}
    return render(request,'buy/sellbook.html',context)

卖书.html

<form method = "post" enctype="multipart/form-data"> 
            {% csrf_token %} 
            {{ form.as_p }} 
            <button type="submit">Upload</button> 
        </form> 

销售应用程序的 urls.py

from django.urls import path

from . import views

urlpatterns = [
    path('sell_book/', views.sell_book,name="sell_book"),
]

追溯

    Environment:


Request Method: POST
Request URL: http://127.0.0.1:8000/sell/sell_book/

Django Version: 3.0.8
Python Version: 3.8.2
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'buy',
 'accounts',
 'sell']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback (most recent call last):
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\django\db\backends\mysql\base.py", line 74, in execute
    return self.cursor.execute(query, args)
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\MySQLdb\cursors.py", line 206, in execute
    res = self._query(query)
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\MySQLdb\cursors.py", line 319, in _query
    db.query(q)
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\MySQLdb\connections.py", line 259, in query
    _mysql.connection.query(self, query)

The above exception ((1146, "Table 'buysell.sell_sellform' doesn't exist")) was the direct cause of the following exception:
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "E:\4th yr project\django book resale project\buy_sell\sell\views.py", line 11, in sell_book
    form.save()
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\django\forms\models.py", line 459, in save
    self.instance.save()
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\django\db\models\base.py", line 745, in save
    self.save_base(using=using, force_insert=force_insert,
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\django\db\models\base.py", line 782, in save_base
    updated = self._save_table(
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\django\db\models\base.py", line 887, in _save_table
    results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\django\db\models\base.py", line 924, in _do_insert
    return manager._insert(
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\django\db\models\query.py", line 1204, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\django\db\models\sql\compiler.py", line 1392, in execute_sql
    cursor.execute(sql, params)
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\django\db\backends\utils.py", line 100, in execute
    return super().execute(sql, params)
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\django\db\backends\utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\django\db\utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\django\db\backends\mysql\base.py", line 74, in execute
    return self.cursor.execute(query, args)
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\MySQLdb\cursors.py", line 206, in execute
    res = self._query(query)
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\MySQLdb\cursors.py", line 319, in _query
    db.query(q)
  File "E:\4th yr project\django book resale project\my_venv\lib\site-packages\MySQLdb\connections.py", line 259, in query
    _mysql.connection.query(self, query)

Exception Type: ProgrammingError at /sell/sell_book/
Exception Value: (1146, "Table 'buysell.sell_sellform' doesn't exist")

而且由于我还想使用表单上传图像,因此我在 settings.py 和 urls.py 的根目录中添加了所需的代码我已经运行了 makemigrations 和 migrate 命令,但我也收到错误消息(1146,“表 'buysell.sell_sellform' 不存在”)。请告诉错误。提前致谢。


解决方案


暂无回答







所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:https://www.pythonheidong.com/blog/article/1533948/9db97c683dd738d0b70d/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

19 0
收藏该文
已收藏

评论内容:(最多支持255个字符)