Python 如何从django上的postgres表名和字段名中删除双引号?
我正在使用postgres处理django项目,其中使用 双引号。有人知道我如何禁用此行为吗 [模型定义]Python 如何从django上的postgres表名和字段名中删除双引号?,python,django,postgresql,Python,Django,Postgresql,我正在使用postgres处理django项目,其中使用 双引号。有人知道我如何禁用此行为吗 [模型定义] class Test1(models.Model): key = models.UUIDField('key', db_column='KEY', editable=False, unique=True, default=uuid.uuid4) name = models.CharField('name', db_column='NAME', max_length=128,
class Test1(models.Model):
key = models.UUIDField('key', db_column='KEY', editable=False, unique=True, default=uuid.uuid4)
name = models.CharField('name', db_column='NAME', max_length=128, null=False)
class Meta:
db_table = 'Test1'
[混合]
operations = [
migrations.CreateModel(
name='Test1',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('key', models.UUIDField(db_column='KEY', default=uuid.uuid4, editable=False, unique=True, verbose_name='key')),
('name', models.CharField(db_column='NAME', max_length=128, verbose_name='name')),
],
options={
'db_table': 'Test1',
},
),
]
[DDL生成]
create table "Test1"
(
id serial not null constraint "Teste4_pkey" primary key,
"KEY" uuid not null constraint "Teste4_KEY_key" unique,
"NAME" varchar(128) not null
);
alter table "Test1" owner to postgres;
[DDL预期值]
create table Test1
(
id serial not null constraint "Teste4_pkey" primary key,
KEY uuid not null constraint "Teste4_KEY_key" unique,
NAME varchar(128) not null
);
alter table "Test1" owner to postgres;
[要求]
- django==2.1.10
- django选项==1.6.1
- django cors标头==2.4.0
- django环境==0.4.5
- django扩展==2.1.4
- djangorestframework==3.8.2
- django过滤器==2.0.0
- drf_yasg==1.14.0
- ruamel.yaml==0.15.100
- drf嵌套路由器==0.91
- dj数据库url==0.5.0
- 请求==2.22
- 白噪声==4.1.3
- 干休息权限==0.1.10
- django多态==2.1.2
- psycopg2==2.7.0
- 弹性apm==4.2.2
- 蛮力==1.0.1
- Jinja2==2.10.3
- 附表==0.6.0
- 鼠兔==1.1.0
- python=1.4.0
- 这是在Django设计的,它是故意以这种方式设计的。这是一种参数化方法。
假设有人的列名带有空格,如
testcolumn name
,然后想想会发生什么。
它将导致一些不必要的错误,因此不要更改框架的基本逻辑。谢谢@bjarniranarsson,正如@Sanjay所提到的,大写字母是框架的这种行为 解决方案:
class Test1(models.Model):
key = models.UUIDField('key', db_column='key', editable=False, unique=True, default=uuid.uuid4)
name = models.CharField('name', db_column='name', max_length=128, null=False)
class Meta:
db_table = 'test1'
我相信这是在django设计的。注意,您正在将db_列名指定为大写,如果“”不存在,则将丢失。这些双引号是否给您带来了一些问题/错误?感谢@BjarniRagnarsson,正如Sanjay提到的那样,大写字母是框架的这种行为。