#28612: inspectdb sets max_length to -1 if no field length specified in the DB
schema
-------------------------------------+-------------------------------------
Reporter: rvernica | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 1.11
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Postgres schema:
{{{
# \d instance
Table "public.instance"
Column | Type | Modifiers
--------------------+-----------------------------+-----------
instance_id | bigint | not null
membership_id | bigint | default 0
host | character varying |
port | integer |
online_since | timestamp without time zone |
base_path | character varying |
server_id | integer |
server_instance_id | integer |
Indexes:
"instance_pkey" PRIMARY KEY, btree (instance_id)
"instance_host_port_key" UNIQUE CONSTRAINT, btree (host, port)
"instance_host_server_id_server_instance_id_key" UNIQUE CONSTRAINT,
btree (host, server_id, server_instance_id)
"instance_server_id_server_instance_id_key" UNIQUE CONSTRAINT, btree
(server_id, server_instance_id)
Check constraints:
"instance_base_path_non_unique" CHECK (check_base_path(base_path) = 0)
}}}
Notice the type for `host` and `base_path` attributes.
`inspectdb` output:
{{{
#!python
# python3 manage.py inspectdb instance
# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
# * Rearrange models' order
# * Make sure each model has one field with primary_key=True
# * Make sure each ForeignKey has `on_delete` set to the desired
behavior.
# * Remove `managed = False` lines if you wish to allow Django to
create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or
field names.
from __future__ import unicode_literals
from django.db import models
class Instance(models.Model):
instance_id = models.BigIntegerField(primary_key=True)
membership_id = models.BigIntegerField(blank=True, null=True)
host = models.CharField(max_length=-1, blank=True, null=True)
port = models.IntegerField(blank=True, null=True)
online_since = models.DateTimeField(blank=True, null=True)
base_path = models.CharField(max_length=-1, blank=True, null=True)
server_id = models.IntegerField(blank=True, null=True)
server_instance_id = models.IntegerField(blank=True, null=True)
class Meta:
managed = False
db_table = 'instance'
unique_together = (('host', 'port'), ('server_id',
'server_instance_id'), ('host', 'server_id', 'server_instance_id'),)
}}}
Notice the `max_length=-1` for `host` and `base_path` attributes.
The `django.contrib.postgres` app is listed in `INSTALLED_APPS`
PostgreSQL `9.6.5`
Python `3.6.1`
Django `1.11.5`
--
Ticket URL: <https://code.djangoproject.com/ticket/28612>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.400856a2e26adb67be6cd6b752bed26b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.