mysql:operationalerror at/(1054,“字段列表”中的未知列“”)

bvhaajcl  于 2021-06-25  发布在  Mysql
关注(0)|答案(0)|浏览(449)

我用这些命令成功地完成了所有迁移。

python manage.py makemigrations senty
python manage.py migrate

我最后犯了一个错误:

Traceback (most recent call last):
File "/Users/~/anaconda/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
  return self.cursor.execute(sql, params)
File "/Users/~/anaconda/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 71, in execute
  return self.cursor.execute(query, args)
File "/Users/~/anaconda/lib/python3.6/site-packages/MySQLdb/cursors.py", line 250, in execute
  self.errorhandler(self, exc, value)
File "/Users/~/anaconda/lib/python3.6/site-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
  raise errorvalue
File "/Users/~/anaconda/lib/python3.6/site-packages/MySQLdb/cursors.py", line 247, in execute
  res = self._query(query)
File "/Users/~/anaconda/lib/python3.6/site-packages/MySQLdb/cursors.py", line 411, in _query
  rowcount = self._do_query(q)
File "/Users/~/anaconda/lib/python3.6/site-packages/MySQLdb/cursors.py", line 374, in _do_query
  db.query(q)
File "/Users/~/anaconda/lib/python3.6/site-packages/MySQLdb/connections.py", line 277, in query
  _mysql.connection.query(self, query)
_mysql_exceptions.OperationalError: (1054, "Unknown column 'senty_score.points' in 'field list'")

The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/~/anaconda/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
  response = get_response(request)
File "/Users/~/anaconda/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
  response = self.process_exception_by_middleware(e, request)
File "/Users/~/anaconda/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
  response = wrapped_callback(request, *callback_args,**callback_kwargs)
File "/Users/~/apps/sentiment/senty/views.py", line 15, in index
  return render(request, 'index.html', context)
File "/Users/~/anaconda/lib/python3.6/site-packages/django/shortcuts.py", line 36, in render
  content = loader.render_to_string(template_name, context, request, using=using)
File "/Users/~/anaconda/lib/python3.6/site-packages/django/template/loader.py", line 62, in render_to_string
  return template.render(context, request)
File "/Users/~/anaconda/lib/python3.6/site-packages/django/template/backends/django.py", line 61, in render
  return self.template.render(context)
File "/Users/~/anaconda/lib/python3.6/site-packages/django/template/base.py", line 175, in render
  return self._render(context)
File "/Users/~/anaconda/lib/python3.6/site-packages/django/template/base.py", line 167, in _render
  return self.nodelist.render(context)
File "/Users/~/anaconda/lib/python3.6/site-packages/django/template/base.py", line 943, in render
  bit = node.render_annotated(context)
File "/Users/~/anaconda/lib/python3.6/site-packages/django/template/base.py", line 910, in render_annotated
  return self.render(context)
File "/Users/~/anaconda/lib/python3.6/site-packages/django/template/defaulttags.py", line 168, in render
  len_values = len(values)
File "/Users/~/anaconda/lib/python3.6/site-packages/django/db/models/query.py", line 254, in __len__
  self._fetch_all()
File "/Users/~/anaconda/lib/python3.6/site-packages/django/db/models/query.py", line 1179, in _fetch_all
  self._result_cache = list(self._iterable_class(self))
File "/Users/~/anaconda/lib/python3.6/site-packages/django/db/models/query.py", line 54, in __iter__
  results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/Users/~/anaconda/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1064, in execute_sql
  cursor.execute(sql, params)
File "/Users/~/anaconda/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
  return super().execute(sql, params)
File "/Users/~/anaconda/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
  return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/Users/~/anaconda/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
  return executor(sql, params, many, context)
File "/Users/~/anaconda/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
  return self.cursor.execute(sql, params)
File "/Users/~/anaconda/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
  raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Users/~/anaconda/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
  return self.cursor.execute(sql, params)
File "/Users/~/anaconda/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 71, in execute
  return self.cursor.execute(query, args)
File "/Users/~/anaconda/lib/python3.6/site-packages/MySQLdb/cursors.py", line 250, in execute
  self.errorhandler(self, exc, value)
File "/Users/~/anaconda/lib/python3.6/site-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
  raise errorvalue
File "/Users/~/anaconda/lib/python3.6/site-packages/MySQLdb/cursors.py", line 247, in execute
  res = self._query(query)
File "/Users/~/anaconda/lib/python3.6/site-packages/MySQLdb/cursors.py", line 411, in _query
  rowcount = self._do_query(q)
File "/Users/~/anaconda/lib/python3.6/site-packages/MySQLdb/cursors.py", line 374, in _do_query
  db.query(q)
File "/Users/~/anaconda/lib/python3.6/site-packages/MySQLdb/connections.py", line 277, in query
  _mysql.connection.query(self, query)
 django.db.utils.OperationalError: (1054, "Unknown column 'senty_score.points' in 'field list'")

在我看来,“点”就在类中,它成功地迁移了。最新的pycache也有正确的类版本,这是以前的错误。直到我从一个不同的函数调用中改变了点,我才发现这个错误。
对mysql来说相当缺乏经验,所以这是一个困难的问题。我必须手动添加列吗?
型号.py

from django.db import models
from datetime import datetime
from decimal import Decimal

class score(models.Model):
    ticker = models.CharField(max_length=10)
    points = models.DecimalField(max_digits=4, decimal_places=1)
    created_at = models.DateTimeField(default=datetime.now, blank=True)

生成迁移输出:

$ python manage.py makemigrations senty
No changes detected in app 'senty'

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题