I’m developing this app in Django where I can’t generate the migrations under any circumstances. I have tried other posts on SO, I have spent hours on ChatGPT, but there’s no progress. After defining the single model, views and urls, my project is always returning django.db.utils.OperationalError: no such table: vini_rest_plotdata in the code that I will provide below.
Can anyone see what is happening here? I have tried to create a whole new project only to find the same error, so I don’t believe it is an error in the settings, but something I have in the code that I am repeating but just can’t see.
views.py:
from django.shortcuts import render
from django.http import JsonResponse
from .models import plotData
from .dash_app import app
import json
# Create your views here.
def import_json(request):
if request.method == 'POST':
data = json.loads(request.body)
title = data.get('title')
description = data.get('description')
url = data.get('url')
json_data = data.get('json_data')
plot_data = plotData.objects.create(
title = title,
description = description,
url = url,
json_data = json_data,
)
return JsonResponse({'status': 'success', 'id': plot_data.id})
else:
return JsonResponse({'status': 'error',
'message': 'Only POST requests are allowed'})
models.py:
class plotData(models.Model):
title = models.CharField(max_length = 100, primary_key=True, unique=True)
description = models.TextField()
url = models.URLField()
json_data = models.JSONField()
urls.py
from django.urls import path, include
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from django.contrib import admin
from django.urls import path
from vini_rest import views
from vini_rest.dash_app import app as dash_app
schema_view = get_schema_view(
openapi.Info(
title = "Vini API",
default_version = "v0.01",
description = "API para o site teste de consulta de dados sobre"
"vinícolas do Brasil pela Embrapa",
terms_of_service = "",
contact = openapi.Contact(email = "[email protected]"),
license = openapi.License(name = "MIT License")
),
public = True,
permission_classes = (permissions.AllowAny,),
)
urlpatterns = [
path('admin/', admin.site.urls),
path('swagger/', schema_view.with_ui("swagger", cache_timeout = 0), name="schema-swagger-ui"),
path('redoc/', schema_view.with_ui('redoc', cache_timeout = 0), name = 'schema_redoc'),
path('django_plotly_dash/', include('django_plotly_dash.urls')),
path('import_json/', views.import_json, name='import_json'),
path('dashboard_view/', views.dashboard_view, name='dashboard_view'),
path('dash_app/', dash_app.server.routes),
]
setting.py | admin.py | apps.py
from django.apps import AppConfig
class ViniRestConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'vini_rest'
------------------------------------------
from django.contrib import admin
from .models import plotData
# Register your models here.
admin.site.register(plotData)
------------------------------------------
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
# BASE_DIR = Path(__file__).resolve().parent.parent
BASE_DIR = Path(__file__).resolve().parent.parent
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',
'django_plotly_dash.apps.DjangoPlotlyDashConfig',
'vini_rest',
'drf_yasg',
]
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 = 'TC_Embrapa.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 = 'TC_Embrapa.wsgi.application'
X_FRAME_OPTIONS = 'SAMEORIGIN'
# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'USER': 'mydatabaseuser',
'PASSWORD': 'mypassword',
'HOST': 'localhost',
'PORT': '8000',
}
}
#DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3', # Change this to match your database engine
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), # Change this to match your database file path
# }
#}
# Password validation
# https://docs.djangoproject.com/en/5.0/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',
},
]
#REST_FRAMEWORK = {
# 'DEFAULT_PERMISSION_CLASSES': (
# 'rest_framework.permissions.IsAuthenticated',
# ),
# 'DEFAULT_AUTHENTICATION_CLASSES': (
# 'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
# 'rest_framework.authentication.SessionAuthentication',
# 'rest_framework.authentication.BasicAuthentication',
# ),
#}
# Internationalization
# https://docs.djangoproject.com/en/5.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/
STATIC_URL = 'static/'
# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
import dash
from dash import dcc
from dash import html
import pandas as pd
from dash.dependencies import Input, Output
from .models import plotData
json_data = plotData.objects.all()
dfs = []
for item in json_data:
df = pd.DataFrame(item.json_data)
dfs.append(df)
app = dash.Dash(__name__)
And I’ll also provide the ChatGPT I’m using to find the error just to keep the traceback out of this post: https://chat.openai.com/share/6828a482-a02f-4d0c-b343-190def29ce1a
I have gone over all the possibilities on the terminal commands on:
- python manage.py migrate appname
- python manage.py makemigrations
I have also gone over deleting previous migrations (I did manage it once I tested the server the first time, but erased the migrations without the new model and now here we are).