i'm using sqlite for my database and all my tables are created but one, when i try "python manage.py migrate. i get error: django.db.utils.OperationalError: no such table: pages_cooptrainee.
my models.py file:
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='')
my views.py file:
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')
my db.sqlite3.sql file:
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)
);
edit: this is my settings.py file (i had to cut some of it beacuse stackoverflow says that my post is mostly code):
# 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')
]
CodePudding user response:
We get the opertional error when we try to access that table of database but it is some how deleted or modified by which it cant communicate with your appplication to solve this error
- the easiest one delete your database if data is not important and then run migrate command
- delete your that app migration files then if you can access the data base which you can by xamp or db browser and then run migration again while deleting dont delete the ini.py file in migartion. then run the command python manage.py makemigrations your_app_name then migrate by command python manage.py migrate your_app_name this would resolve your issue
CodePudding user response:
did you try python manage.py makemigrations <your_app>
?
And then you need to python manage.py migrate