[Django]-Db_table option does not work in Django model

4👍

db_table option gives a flexibility to user for specifying a database table name.

From the error it looks like that table gender does not exist in database. That means after specifying this option you haven’t performed syncdb. Please do a syncdb or if you are using south then schemamigration.

3👍

I got the solution, if you want to change you model name using like this..

class Gender(models.Model):
    name = models.CharField(max_length=20)


    class Meta:
        db_table = 'gender'

after that you have to maigrate your model again

  1. python manage.py makemigrations
  2. python manage.py migrate

Leave a comment