Mysql:在/的操作错误(1054,“字段列表中的未知列”')

时间:2018-01-11 08:04:29

标签: python mysql django

我已成功完成了对这些命令的所有迁移。

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,所以这是一个艰难的。我是否必须以某种方式手动添加列?

models.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)

MakeMigrations输出:

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

0 个答案:

没有答案