I'm working on a django project with postgres where table and field names are generated with double quotes. Anyone knows how can I disable this behavior?
[Model definition]
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'
[Migtation]
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 Generated]
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 Expected]
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;
[requirements]
This is by design in Django, and it is intentionally designed in this way. this is a parametrized way.
suppose someone has a column name with spaces like test column name
then think what would happen. it will lead to some unwanted errors, so don't change the underlying logic of the framework.
Thanks @BjarniRagnarsson, The upper case letters was making this behavior of framework as @Sanjay mentioned.
Solution:
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'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.