如何在Django中的其他模式中创建表?

发布于 2025-02-10 22:42:34 字数 324 浏览 1 评论 0原文

我在Django项目中使用了PostgreSQL数据库。

我的项目中有多个应用程序。

users/
    UserProfile model
myapp/
    CustomModel model

现在,我需要userProfile应该在public schema中创建表 Custommodel表需要在一个称为myApp的单独架构中创建表,

如何实现此问题,并且在实现此问题后是否需要更改查询或迁移命令中的任何内容?

I'm using postgresql database in my django project.

I have multiple apps in my projects.

users/
    UserProfile model
myapp/
    CustomModel model

Now I need UserProfile table should be created in public schema
And CustomModel table needs to be created in a separate schema called myapp

How to implement this and Do I need to change anything in the queries or migration command in future after implementing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぃ双果 2025-02-17 22:42:34

只需使用元信息:

class User(models.Model)
    class Meta:
        db_table = 'schema"."tablename'

我从一段时间开始使用它,到目前为止没有问题。

更多信息:
这将用db_table在所有数据库查询中替换表名称。因此,任何查询都会从“ TableName”中选择 *将转换为select *从“ geo”中选择 *。“ tablename”。这只是一个整洁的技巧,希望Django在将来在本来可以提供此选项。

Just use a meta information:

class User(models.Model)
    class Meta:
        db_table = 'schema"."tablename'

I've been using it from some time and found not problem so far.

More info:
This will replace table name in all your database queries with db_table. So any query will SELECT * FROM "tablename" will be converted to SELECT * FROM "geo"."tablename". Its just a neat trick, hopefully Django gives this option natively in future.

美人如玉 2025-02-17 22:42:34

用于SQL Server使用

class User(models.Model)
class Meta:
    db_table = '[schema].[tablename]'

FOr Sql Server Use

class User(models.Model)
class Meta:
    db_table = '[schema].[tablename]'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文