如何在Django中的其他模式中创建表?
我在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需使用元信息:
我从一段时间开始使用它,到目前为止没有问题。
更多信息:
这将用
db_table
在所有数据库查询中替换表名称。因此,任何查询都会从“ TableName”中选择 *
将转换为select *从“ geo”中选择 *。“ tablename”
。这只是一个整洁的技巧,希望Django在将来在本来可以提供此选项。Just use a meta information:
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 willSELECT * FROM "tablename"
will be converted toSELECT * FROM "geo"."tablename"
. Its just a neat trick, hopefully Django gives this option natively in future.用于SQL Server使用
FOr Sql Server Use