Prometheus
Prometheus

Reputation: 33615

Creating alias for the db tableD Django

I'm trying to design some Django models my question is.

How do you create an alias for the db table when if differs from what I want it to be call in the model?

class Person(models.Model):
    name = models.CharField(max_length=30)

database table

core_Person

Upvotes: 1

Views: 229

Answers (2)

rxdazn
rxdazn

Reputation: 1390

class Person(models.Model):
    name = models.CharField(max_length=30)

    class Meta:
        db_table = 'core_Person'

Upvotes: 1

dm03514
dm03514

Reputation: 55952

class Person(models.Model):
  name = models.CharField(max_length=30)

  class Meta:
    db_table = 'core_Person'

from the documenation:

To override the database table name, use the db_table parameter in class Meta.

If you're not familiary with Meta options, django gives you some information about them here

Upvotes: 3

Related Questions