I don't want to use Fake app migrate option for the solution Please suggest any other method for this problem
Do check my code
Models - from django.db import models
from mptt.models import MPTTModel, TreeForeignKey
class Delhi(models.Model):
account_id = models.IntegerField()
type_code = models.CharField(max_length=200)
sub_type_code = models.CharField(max_length=200)
name = models.CharField(max_length=200)
credit_amount = models.IntegerField()
debit_amount = models.IntegerField()
# parent = TreeForeignKey('self', null = True, related_name = 'strctr', on_delete = models.CASCADE)
class Meta:
managed = True
db_table = 'gaur'
def __str__(self):
return self.type_code
class Ranchi(MPTTModel):
node_name = models.CharField(max_length = 100)
parent = TreeForeignKey('self', null = True, related_name = 'strctr', on_delete = models.CASCADE)
def __str__(self):
return self.name
Serializer -
from rest_framework import serializers
from .models import Delhi, Ranchi
class DelhiSerializer(serializers.ModelSerializer):
class Meta:
model = Delhi
fields = "__all__"
class RanchiSerializer(serializers.ModelSerializer):
class Meta:
model = Ranchi
fields = "__all__"
View -
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework import generics
from rest_framework import status
class CreateView(generics.ListCreateAPIView):
"""This class defines the create behavior of our rest api."""
queryset = Delhi.objects.all()
serializer_class = DelhiSerializer
def perform_create(self, serializer):
"""Save the post data when creating a new bucketlist."""
serializer.save()
class DetailsView(generics.RetrieveUpdateDestroyAPIView):
"""This class handles the http GET, PUT and DELETE requests."""
queryset = Delhi.objects.all()
serializer_class = DelhiSerializer
Database name if hello and table name is 'GAUR' as mention in model.
I tried with same syntax with SQLite configuration, it works for SQLite but when I want to work on database thing it shows the given error on -
python manage.py migrate
error is -
Operations to perform:
Apply all migrations: admin, app1, auth, contenttypes, sessions
Running migrations:
Applying app1.0001_initial...Traceback (most recent call last):
. . . . . . _mysql.connection.query(self, query) django.db.utils.OperationalError: (1050, "Table 'gaur' already exists")
python manage.py makemigrations
Please suggest a good solution because I have seen all the links of stack for the similar errors, but does give me desired output.
Virtual environment name is - myproject
I tried my making different project under different virtual environment in case the environment is corrupted, but it didnt work.
I even tried on different location with same virtual environment but result was same.