How to remove the prefix of a table for a Django model?

前端 未结 4 545
难免孤独
难免孤独 2020-12-28 16:17

I create a new Django app (not project) called Bussinesses, then add following class to the models.py.

class Bussinesses(models.Model):
    busi         


        
4条回答
  •  无人及你
    2020-12-28 16:40

    Just use the model meta options.

    class Bussinesses(models.Model):
        business_email = models.EmailField()
        password = models.CharField(max_length=20)
        contact_first_name = models.CharField(max_length=30)
        contact_last_name = models.CharField(max_length=30)
    
        class Meta:
            db_table = "bussinesses"
    

    BTW businesses is misspelled. Since you're specifying the name of the table you don't have to give your model the same name as the table, so if the table name is misspelled and you can't easily fix it, you can at least change the name of your class to the proper spelling of businesses. I would also get rid of the pluralization, and make it class Business. Finally it's not uncommon when using Django or Rails on an existing database to need to set a custom table name for every table.

提交回复
热议问题