Opened 8 years ago
Closed 8 years ago
#28133 closed Bug (invalid)
KeyError: u'blank' or KeyError: u'editable' when upgrading django
Reported by: | latheef | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 1.8 |
Severity: | Normal | Keywords: | upgrade django, KeyError: u'blank', KeyError: u'editable' |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Seems this error is oftenly coming when doing makemigrations
or migrate
commad.
In django 1.8, line is
https://github.com/django/django/blob/1.8/django/db/models/fields/__init__.py#L1252
if self.auto_now or self.auto_now_add: del kwargs['editable'] del kwargs['blank']
This is not checking whether field is there or not. Can solve it by
if self.auto_now or self.auto_now_add: if 'editable' in kwargs: del kwargs['editable'] if 'blank' in kwargs: del kwargs['blank']
After some digging I can see the problem is happening because of deconstruct
method in Field
class.
The place where above kwargs
getting is
keywords = {} possibles = { "verbose_name": None, "primary_key": False, "max_length": None, "unique": False, "blank": False, "null": False, "db_index": False, "default": NOT_PROVIDED, "editable": True, "serialize": True, "unique_for_date": None, "unique_for_month": None, "unique_for_year": None, "choices": [], "help_text": '', "db_column": None, "db_tablespace": settings.DEFAULT_INDEX_TABLESPACE, "auto_created": False, "validators": [], "error_messages": None, } attr_overrides = { "unique": "_unique", "choices": "_choices", "error_messages": "_error_messages", "validators": "_validators", "verbose_name": "_verbose_name", } equals_comparison = {"choices", "validators", "db_tablespace"} for name, default in possibles.items(): value = getattr(self, attr_overrides.get(name, name)) # Unroll anything iterable for choices into a concrete list if name == "choices" and isinstance(value, collections.Iterable): value = list(value) # Do correct kind of comparison if name in equals_comparison: if value != default: keywords[name] = value else: if value is not default: keywords[name] = value
Here, it is not returning keys editable
or blank
sometimes based on if condition.Thats why it is happening.
Change History (3)
comment:1 by , 8 years ago
Component: | Uncategorized → Migrations |
---|
comment:2 by , 8 years ago
I got it why this is happening. If override DateField
like http://ianrolfe.livejournal.com/36017.html
class MyDateField(models.DateField): def __init__(self, null=False, blank=False, **kwargs): super(MyDateField, self).__init__(**kwargs) self.editable = True #This will give key error 'editable' self.blank = False #This will give key error 'blank'
Above code is working for syncdb(older). But this gettings error when makemigrations
and migrate
command versions of django.
comment:3 by , 8 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
I don't think this is a bug in Django. Please see Field deconstruction and use TicketClosingReasons/UseSupportChannels if you need further help.
Can you please add steps or a sample project to reproduce the issue?