Djagno 3.0和Python3.6.12 1054错误,遵循Django 3.0教程 大家好! 首先,我想向这个社区更好地介绍我自己。我在Python方面介于初学者和中级之间,但在Linux和MS System Admini方面处于高级。所以我熟悉PHP、CSS、HTML、LAMP、XAMP、XMPP、DNS、虚拟化、云计算等等。。。。全部的但是,关于编程,我从Pasqual开始,然后是VisualBasic,在学习了一点Java之后,我开始专注于Python。
CPU:(对不起,我有点老了:i686(32位) 内存:4 GB 操作系统:Ubuntu操作系统18.04 LTSDjagno 3.0和Python3.6.12 1054错误,遵循Django 3.0教程 大家好! 首先,我想向这个社区更好地介绍我自己。我在Python方面介于初学者和中级之间,但在Linux和MS System Admini方面处于高级。所以我熟悉PHP、CSS、HTML、LAMP、XAMP、XMPP、DNS、虚拟化、云计算等等。。。。全部的但是,关于编程,我从Pasqual开始,然后是VisualBasic,在学习了一点Java之后,我开始专注于Python。,python,python-3.x,linux,pycharm,virtualenv,Python,Python 3.x,Linux,Pycharm,Virtualenv,CPU:(对不起,我有点老了:i686(32位) 内存:4 GB 操作系统:Ubuntu操作系统18.04 LTS 然而,让我们跳到我的问题,我得到的错误: 在学习了一些教程之后 我得到以下信息: (Django) root@borisdev:/home/Desktop/DjangoRelationships/MyProject# python manage.py shell Python 3.6.12 (default, Aug 18 2020, 02:08:22) [GCC 5.4.0
- 然而,让我们跳到我的问题,我得到的错误:
(Django) root@borisdev:/home/Desktop/DjangoRelationships/MyProject# python manage.py shell
Python 3.6.12 (default, Aug 18 2020, 02:08:22)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from MyApp.models import Article, Reporter
>>> r = Reporter(first_name = 'John', last_name = 'Doe', email = 'abc@somemail.com')
>>> r.save()
>>> r1 = Reporter(first_name = 'Boris', last_name = 'Milanovic', email = 'milanvociful@gmail.com')
>>> r1.save()
>>> from datetime import date
>>> a = Article(headline = 'This is my first article', pub_date = date(2020, 10, 10), reporter=r)
>>> a.save()
Traceback (most recent call last):
File "/home/Desktop/Django/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/Desktop/Django/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 73, in execute
return self.cursor.execute(query, args)
File "/home/Desktop/Django/lib/python3.6/site-packages/MySQLdb/cursors.py", line 206, in execute
res = self._query(query)
File "/home/Desktop/Django/lib/python3.6/site-packages/MySQLdb/cursors.py", line 319, in _query
db.query(q)
File "/home/Desktop/Django/lib/python3.6/site-packages/MySQLdb/connections.py", line 259, in query
_mysql.connection.query(self, query)
MySQLdb._exceptions.OperationalError: (1054, "Unknown column 'reporter_id' in 'field list'")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/Desktop/Django/lib/python3.6/site-packages/django/db/models/base.py", line 754, in save
force_update=force_update, update_fields=update_fields)
File "/home/Desktop/Django/lib/python3.6/site-packages/django/db/models/base.py", line 792, in save_base
force_update, using, update_fields,
File "/home/Desktop/Django/lib/python3.6/site-packages/django/db/models/base.py", line 895, in _save_table
results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
File "/home/Desktop/Django/lib/python3.6/site-packages/django/db/models/base.py", line 935, in _do_insert
using=using, raw=raw,
File "/home/Desktop/Django/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/Desktop/Django/lib/python3.6/site-packages/django/db/models/query.py", line 1254, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "/home/Desktop/Django/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1397, in execute_sql
cursor.execute(sql, params)
File "/home/Desktop/Django/lib/python3.6/site-packages/django/db/backends/utils.py", line 98, in execute
return super().execute(sql, params)
File "/home/Desktop/Django/lib/python3.6/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/Desktop/Django/lib/python3.6/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/Desktop/Django/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/Desktop/Django/lib/python3.6/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/Desktop/Django/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/Desktop/Django/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 73, in execute
return self.cursor.execute(query, args)
File "/home/Desktop/Django/lib/python3.6/site-packages/MySQLdb/cursors.py", line 206, in execute
res = self._query(query)
File "/home/Desktop/Django/lib/python3.6/site-packages/MySQLdb/cursors.py", line 319, in _query
db.query(q)
File "/home/Desktop/Django/lib/python3.6/site-packages/MySQLdb/connections.py", line 259, in query
_mysql.connection.query(self, query)
django.db.utils.OperationalError: (1054, "Unknown column 'reporter_id' in 'field list'")
>>>
(Django)root@borisdev:/home/Desktop/djangorrelationships/MyProject#python manage.py shell
Python 3.6.12(默认值,2020年8月18日,02:08:22)
[GCC 5.4.0 20160609]在linux上
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
(InteractiveConsole)
>>>来自MyApp.models导入文章,Reporter
>>>r=记者(名字='John',姓氏='Doe',电子邮件='abc@somemail.com')
>>>r.save()
>>>r1=记者(名字='Boris',姓氏='Milanovic',电子邮件='milanvociful@gmail.com')
>>>r1.save()
>>>起始日期时间导入日期
>>>a=文章(标题='这是我的第一篇文章',发布日期=日期(2020,10,10),记者=r)
>>>a.保存()
回溯(最近一次呼叫最后一次):
文件“/home/Desktop/Django/lib/python3.6/site packages/Django/db/backends/utils.py”,第84行,在
返回self.cursor.execute(sql,params)
文件“/home/Desktop/Django/lib/python3.6/site packages/Django/db/backends/mysql/base.py”,第73行,在execute中
返回self.cursor.execute(查询,参数)
文件“/home/Desktop/Django/lib/python3.6/site packages/MySQLdb/cursors.py”,执行中的第206行
res=自我查询(查询)
文件“/home/Desktop/Django/lib/python3.6/site packages/MySQLdb/cursors.py”,第319行,在
数据库查询(q)
文件“/home/Desktop/Django/lib/python3.6/site packages/MySQLdb/connections.py”,查询中的第259行
_mysql.connection.query(self,query)
MySQLdb._exceptions.OperationalError:(1054,“字段列表”中的未知列'reporter_id')
上述异常是以下异常的直接原因:
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“/home/Desktop/Django/lib/python3.6/site packages/Django/db/models/base.py”,第754行,保存
强制更新=强制更新,更新字段=更新字段)
文件“/home/Desktop/Django/lib/python3.6/site packages/Django/db/models/base.py”,第792行,在save_base中
强制更新,使用,更新字段,
文件“/home/Desktop/Django/lib/python3.6/site packages/Django/db/models/base.py”,第895行,在保存表格中
结果=self.\u do\u insert(cls.\u基本\u管理器,使用,字段,返回\u字段,原始)
文件“/home/Desktop/Django/lib/python3.6/site packages/Django/db/models/base.py”,第935行,插入
使用=使用,原始=原始,
文件“/home/Desktop/Django/lib/python3.6/site packages/Django/db/models/manager.py”,第85行,在manager_方法中
返回getattr(self.get_queryset(),name)(*args,**kwargs)
文件“/home/Desktop/Django/lib/python3.6/site packages/Django/db/models/query.py”,第1254行,插入
return query.get\u编译器(using=using).execute\u sql(返回\u字段)
文件“/home/Desktop/Django/lib/python3.6/site packages/Django/db/models/sql/compiler.py”,第1397行,在execute_sql中
cursor.execute(sql,params)
文件“/home/Desktop/Django/lib/python3.6/site packages/Django/db/backends/utils.py”,执行中的第98行
return super().execute(sql,params)
文件“/home/Desktop/Django/lib/python3.6/site packages/Django/db/backends/utils.py”,第66行,在execute中
返回self.\u使用包装器执行(sql,params,many=False,executor=self.\u execute)
文件“/home/Desktop/Django/lib/python3.6/site packages/Django/db/backends/utils.py”,第75行,使用包装器执行
返回执行器(sql、参数、多个、上下文)
文件“/home/Desktop/Django/lib/python3.6/site packages/Django/db/backends/utils.py”,第84行,在
返回self.cursor.execute(sql,params)
文件“/home/Desktop/Django/lib/python3.6/site packages/Django/db/utils.py”,第90行,在__
使用exc_值的_回溯(回溯)提高dj_exc_值
文件“/home/Desktop/Django/lib/python3.6/site packages/Django/db/backends/utils.py”,第84行,在
返回self.cursor.execute(sql,params)
文件“/home/Desktop/Django/lib/python3.6/site packages/Django/db/backends/mysql/base.py”,第73行,在execute中
返回self.cursor.execute(查询,参数)
文件“/home/Desktop/Django/lib/python3.6/site packages/MySQLdb/cursors.py”,执行中的第206行
res=自我查询(查询)
文件“/home/Desktop/Django/lib/python3.6/site packages/MySQLdb/cursors.py”,第319行,在
数据库查询(q)
文件“/home/Desktop/Django/lib/python3.6/site packages/MySQLdb/connections.py”,查询中的第259行
_mysql.connection.query(self,query)
django.db.utils.OperationalError:(1054,“字段列表”中的未知列'reporter_id')
>>>
如果需要任何额外的资源,请让我知道到目前为止我最好的朋友“谷歌”能够解决
谢谢大家!
~Boris我也有同样的问题:
以下是我的设置.py:
"""
Django settings for RelationshipsInDjango project.
Generated by 'django-admin startproject' using Django 3.1.2.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '4umiwx4$3p6c2e7!x)+5kk0*s4py5e5n+ecn7=efskcer4@6v$@'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'MyApp'
]
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',
]
ROOT_URLCONF = 'RelationshipsInDjango.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'RelationshipsInDjango.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mydjango',
'USER': 'debian-sys-maint',
'PASSWORD': '6LJl7CAz9Lyuxxxx',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/'
似乎缺少或未应用迁移。我已完成makemigrations和migrate…。更新:(Django)root@borisdev:/home/Desktop/Django关系/MyProject#python manage.py makemigrations未检测到任何更改(Django) root@borisdev:/home/Desktop/djangorationships/MyProject#python manage.py要执行的迁移操作:应用所有迁移:MyApp、admin、auth、contenttypes、运行迁移的会话:应用MyApp.0002_auto_20201013_0704…回溯(最近一次调用):File“/home/Desktop/Django/lib/python3.6/site packages/Django/db/backends/utils.py”,第82行,在执行返回self.cursor.execute(sql)中,您是否在