Last Updated: February 25, 2016
·
13.94K
· piccoloaiutante

Custom table name in Django model

If you want to map an existing table to a django model you have just to use the db_table property of the Meta class of your django model.
Here you have an easy example:

class User(models.Model):
    class Meta:
        db_table = 'my_user_table'

    name = models.CharField(max_length=200)
    surname = models.CharField(max_length=200)

In this example you can see how to map a django model class called User over a custom table called myusertable.