簡體   English   中英

django復制遷移表的模型名稱

[英]django duplicates the name of model for migration table

當我遷移django 2模型時,它制作的表沒有任何問題,但是表的名稱是這樣的:‌nameofmodel_nameofmodel !!! 例如,booking_booking !!! 這是我的代碼:

    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 )

這是我的序列化器:

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',
         )

那么django的標准命名是什么?如果我想以其他方式使用它,我是否做得正確?

您可以這樣:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM