我正在為我的資料庫使用 sqlite 并且我的所有表都被創建,但是當我嘗試“python manage.py migrate.我得到錯誤:django.db.utils.OperationalError:沒有這樣的表:pages_cooptrainee。
我的models.py檔案:
class cooptrainee(models.Model): # ??????? ????????
Name = models.CharField(max_length=100,default='')
College = models.CharField(max_length=40,default='')
Major = models.CharField(max_length=30,default='')
Gpa = models.CharField(max_length=4,default='')
Email = models.CharField(max_length=60,default='')
phoneNumber = models.CharField(max_length=15,default='')
我的 views.py 檔案:
def CoopTraining(request):
Name = request.POST.get('Name')
College = request.POST.get('College')
Major = request.POST.get('Major')
GPA = request.POST.get('GPA')
Email = request.POST.get('Email')
phoneNumber = request.POST.get('Phone Number')
trainingPeriod = request.POST.get('Training Period')
if request.method == 'POST':
data = cooptrainee(Name=Name,College=College,Major=Major,GPA=GPA,Email=Email,phoneNumber=phoneNumber,trainingPeriod=trainingPeriod)
data.save()
return render(request,'pages/??????? ????????.html')
我的 db.sqlite3.sql 檔案:
CREATE TABLE IF NOT EXISTS "pages_cooptrainee" (
"id" integer NOT NULL,
"Name" varchar(100) NOT NULL,
"College" varchar(40) NOT NULL,
"Major" varchar(30) NOT NULL,
"Gpa" varchar(4) NOT NULL,
"Email" varchar(60) NOT NULL,
"phoneNumber" varchar(15) NOT NULL,
PRIMARY KEY("id" AUTOINCREMENT)
);
編輯:這是我的 settings.py 檔案(我不得不削減其中的一些,因為 stackoverflow 說我的帖子主要是代碼):
# Application definition
INSTALLED_APPS = [
'pages.apps.PagesConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
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 = 'project.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'templates')],
'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 = 'project.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR,'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR,'project/static')
]
uj5u.com熱心網友回復:
當我們嘗試訪問該資料庫表時,我們收到了操作錯誤,但它無法與您的應用程式通信以解決此錯誤的洗掉或修改方式
- 如果資料不重要,最簡單的方法是洗掉資料庫,然后運行 ??migrate 命令
- 洗掉您的應用程式遷移檔案,然后如果您可以通過 xamp 或 db 瀏覽器訪問資料庫,然后再次運行遷移,同時洗掉不要洗掉遷移中的 ini.py 檔案。然后運行命令 python manage.py makemigrations your_app_name 然后通過命令遷移 python manage.py migrate your_app_name 這將解決你的問題
uj5u.com熱心網友回復:
你試過python manage.py makemigrations <your_app>嗎?然后你需要python manage.py migrate
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/347613.html
上一篇:PHP$_SESSION陣列在前端生產構建中為空,但在開發構建中不是
下一篇:如何測驗Django模型欄位
