2

So basically i created a new Django project and an app which contains my model. I have already created a free cluster on mongoDb atlas and connected my project via Djongo engine.

Issues:

when i first made make migrations and then migrated my model , it created a new database from scratch since i had not created it. however my model name is Mtsdata and would like to create a corresponding collection. why is the collection not created though it shows in the migration files that i have created the model and also in my database , my django_migrations is updated ?

from django.db import models

class Mtsdata(models.Model):
Company = models.CharField(max_length= 32 , null=True, blank=True)
plant = models.CharField(max_length= 32 , null=True, blank=True)
    class Meta:
        managed = False
        db_table = "Mtsdata"

urls.py

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


urlpatterns = [
    path('admin/', admin.site.urls),
    path('mtsdata/',views.Mtsdatalist.as_view()),
]

views.py

from django.shortcuts import render
from . models import Mtsdata
from django.http import HttpResponse
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
from rest_framework.generics import ListCreateAPIView, RetrieveUpdateDestroyAPIView, ListAPIView
# Create your views here.

class Mtsdatalist(ListAPIView):
    
    def get(self,request):
        queryset = Mtsdata.objects.all()
      
        return Response(queryset.values())
Ravi Shankar Bharti
  • 8,922
  • 5
  • 28
  • 52
yukta
  • 21
  • 1
  • 6

0 Answers0