Reputation: 4115
I want to remove the app label from the table name hence i have a extremely simple web application.
I am using following model:
class Gender(models.Model):
name = models.CharField(max_length=20)
class Meta:
db_table = 'gender'
The result is not quite as expected:
>>> Gender.objects.all()
ProgrammingError: (1146, "Table 'project.gender' doesn't exist")
Why is the meta option not working?
I am using Django 1.6.2
Upvotes: 3
Views: 8266
Reputation: 31
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
python manage.py makemigrations
python manage.py migrate
Upvotes: 3
Reputation: 3114
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
.
Upvotes: 4