Farshad
Farshad

Reputation: 2000

django duplicates the name of model for migration table

when i migrate my django 2 models it makes tables without any problem but the name of table is like this :‌nameofmodel_nameofmodel !!! so for example booking_booking !!! here is my code :

    from django.db import models


# Create your models here.
class Booking(models.Model):
    user_id = models.CharField(max_length=50, null=True )
    operator_id = models.CharField(max_length=50, null=True )
    computed_net_price = models.CharField(max_length=50, null=True )
    final_net_price = models.CharField(max_length=50, null=True )
    payable_price = models.CharField(max_length=50, null=True )
    booking_status = models.CharField(max_length=50, null=True )
    guest_name = models.CharField(max_length=50, null=True )
    guest_last_name = models.CharField(max_length=50, null=True )
    guest_cellphone = models.CharField(max_length=50, null=True )
    from_date = models.DateTimeField(max_length=50, null=True )
    to_date = models.DateTimeField(max_length=50, null=True )
    is_removed = models.IntegerField(null=True )

and here is my serializer :

from rest_framework import serializers
from .models import Booking
class BookingSerializer(serializers.ModelSerializer):
     class Meta:
         model = Booking
         fields =(
             'user_id',
             'computed_net_price',
             'final_net_price',
             'payable_price',
             'booking_status',
             'booking_status',
             'guest_name',
             'guest_last_name',
             'guest_cellphone',
             'guest_cellphone',
             'guest_cellphone',
             'operator_id',
             'is_removed',
         )

so what is the standard naming of django and what if i want to have it in a different way and i am doing correctly or not

Upvotes: 0

Views: 321

Answers (1)

Vladislav Vasyukov
Vladislav Vasyukov

Reputation: 141

You can make like that:

class YourModel(models.Model):
    # first_field = ....
    # second_field = ....

    class Meta:
        db_table = 'table_name'

https://docs.djangoproject.com/en/2.2/topics/db/models/#meta-options

Upvotes: 1

Related Questions