Error in trying to connect Model to ModelForm in Django

I'm learning Django and am trying to make a request form to fill by using Django and an MySQL database and i am encountering issues trying to connect to making a ModelForm with a database and table i have already created. It returns this error specifically

(envworld) C:\Seen\Documents\envworld\myweb>python makemigrations
Traceback (most recent call last):
  File "C:\Seen\Documents\envworld\myweb\", line 22, in <module>
  File "C:\Seen\Documents\envworld\myweb\", line 18, in main
  File "C:\Seen\Documents\envworld\lib\site-packages\django\core\management\", line 446, in execute_from_command_line      
  File "C:\Seen\Documents\envworld\lib\site-packages\django\core\management\", line 420, in execute
  File "C:\Seen\Documents\envworld\lib\site-packages\django\", line 24, in setup
  File "C:\Seen\Documents\envworld\lib\site-packages\django\apps\", line 124, in populate
  File "C:\Seen\Documents\envworld\lib\site-packages\django\contrib\admin\", line 27, in ready
  File "C:\Seen\Documents\envworld\lib\site-packages\django\contrib\admin\", line 50, in autodiscover
    autodiscover_modules("admin", register_to=site)
  File "C:\Seen\Documents\envworld\lib\site-packages\django\utils\", line 58, in autodiscover_modules
    import_module("%s.%s" % (, module_to_search))
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0\lib\importlib\", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Seen\Documents\envworld\myweb\formsite\", line 2, in <module>
    from .forms import RequestForm
  File "C:\Seen\Documents\envworld\myweb\formsite\", line 12, in <module>
    request = Request_Form.objects.get(pk=1)
  File "C:\Seen\Documents\envworld\lib\site-packages\django\db\models\", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "C:\Seen\Documents\envworld\lib\site-packages\django\db\models\", line 650, in get
    raise self.model.DoesNotExist(
formsite.models.Request_Form.DoesNotExist: Request_Form matching query does not exist.

here is also the file directory for the Django project and app

Django project & app path

I'm assuming that the problem is with the Request_Form.objects.get(pk=1) since i defined the primary key while django automatically creates a field/column when its not declared through AutoField() but i am also asking in advance if there are any issues from the code

here is the code and what i did

from django.db import models

class Request_Form (models.Model):
    No_Permintaan = models.IntegerField(primary_key=True)
    Nama_Aplikasi = models.CharField(max_length=30)
    Departemen = models.CharField(max_length=50)
    Description = models.TextField(max_length=2000)
    TanggalReq = models.DateTimeField
    Nama_Atasan = models.CharField(max_length=30, unique=True)

    def __str__(self):
        return self.Nama_Aplikasi
class Serah_Terima (models.Model):
    Kode_Permintaan = models.ForeignKey(Request_Form, on_delete=models.CASCADE)
    TanggalApproval = models.DateField
    Atasan = models.ForeignKey(Request_Form, on_delete=models.CASCADE,to_field='Nama_Atasan' ,related_name='Kode_Permintaan')
    Comment = models.TextField

    def __str__(self):

from django.db import models
from django.forms import ModelForm
from formsite.models import Request_Form
from formsite.models import Serah_Terima

class RequestForm(ModelForm):
        class Meta:
                model = Request_Form
                fields = ['Nama_Aplikasi', 'Departemen', 'Description', 'Nama_Atasan']
form = RequestForm()
request = Request_Form.objects.get(pk=1)
form = RequestForm(instance=request)

class SerahTerima(ModelForm):
   class Meta:
        model = Serah_Terima
        fields = ['Tanggal_Approval','Nama_Atasan','Comment']

form = SerahTerima()
serah = SerahTerima.objects.get(pk=1)
form = SerahTerima(instance=request)

i have commented the Serah_Terima part of the form as i am still testing the Request_Form modelform but here is also the rest of the code

from django.shortcuts import render
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from .forms import RequestForm
def welcome(request):
    return HttpResponse("Welcome to the Home Page")

def formpage(request):
    submitted = False
    if request.method == 'POST':
        form= RequestForm(request.POST)
        if form.is_valid():
            return HttpResponseRedirect('myweb/formpage?submitted=True')
            form = RequestForm
            if 'submitted' in request.GET:
                submitted = True
            return render(request, 'myweb/formpage.html', {'form':form,'submitted':submitted}) myweb/formsite/

from django.urls import path
from formsite import views

urlpatterns = [
    path('form/', views.formpage, name = 'formpage'),
    path('', views.welcome, name='welcome'),
] myweb/

from django.contrib import admin
from django.urls import path
from formsite import views

urlpatterns = [
    path('', views.welcome, name='home'),
    path('form/', views.formpage, name = 'formpage'),

and then the html codes just in case


{% {% extends 'base.html' %}%}
<h2>For App Request </h2>

{%if submitted%}
    Data is Submitted
{% else %}

    {% csrf_token %}
    {{ form.as_p }}
        <input type="Submit" value="Submit">
{% endif %}


<!DOCTYPE !html>

<html lang="en">
    <link rel="stylesheet" href="style.css">`
    <title>Form Login Page</title>

    <div id="sidebar">
            <li><a href="/myweb">Home</a></li>
            <li><a href="myweb/formpage">formpage</a></li>


your should look like this

from django import forms
from formsite.models import Request_Form
from formsite.models import Serah_Terima

class RequestForm(forms.ModelForm):
    class Meta:
        model = Request_form
        fields = ['Nama_Aplikasi', 'Departemen', 'Description', 'Nama_Atasan']

This one below is meant to be in your

form = RequestForm()
request = Request_Form.objects.get(pk=1)
form = RequestForm(instance=request)
Back to Top