python - 为 db tableD Django 创建别名

标签 python django django-models

我正在尝试设计一些 Django 模型,我的问题是。

当 if 与我希望它在模型中调用的不同时,如何为 db 表创建别名?

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

数据库表

core_Person

最佳答案

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

  class Meta:
    db_table = 'core_Person'

来自 documenation :

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

如果您不熟悉 Meta 选项,django 会为您提供一些有关它们的信息 here

关于python - 为 db tableD Django 创建别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13767359/

相关文章:

python - python中逐列求和两个文件

Python scikit svm "ValueError: X has 62 features per sample; expecting 337"

python - 奇怪的 Docker + Celery Bug

python - 在 Python 2.7 中如何将文本 (.txt) 文件作为 .py 文件读取?

django - Django:对抽象模型进行单元测试的最佳方法

python - 使用外键在 Django 中抽象基类继承

python - 如何通过url传递django中的变量?

针对 LDAP 的 Django 用户身份验证 - 多个组

django - 在 Django 上使用 select_lated 进行过滤

django - Django 中 User.objects.create_user() 与 User.objects.create() 与 User().save() 之间的区别