question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

If blank=True, it's impossible to save an empty phone number

See original GitHub issue

If you define a field like this in your models.py:

    faxnumber = PhoneNumberField(u'Fax',max_length=40,blank=True)

You'll have this backtrace:

Environment:


Request Method: POST
Request URL: http://morphee.hq.eyepea.be:8001/admin/xivo_web/entity/3/

Django Version: 1.3.1
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'xivo_web']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/options.py" in wrapper
  307.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/utils/decorators.py" in _wrapped_view
  93.                     response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  79.         response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py" in inner
  197.             return view(request, *args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/utils/decorators.py" in _wrapper
  28.             return bound_func(*args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/utils/decorators.py" in _wrapped_view
  93.                     response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/utils/decorators.py" in bound_func
  24.                 return func(self, *args2, **kwargs2)
File "/usr/lib/python2.5/site-packages/django/db/transaction.py" in inner
  217.                 res = func(*args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/options.py" in change_view
  982.                 self.save_model(request, new_object, form, change=True)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/options.py" in save_model
  665.         obj.save()
File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in save
  460.         self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in save_base
  526.                         rows = manager.using(using).filter(pk=pk_val)._update(values)
File "/usr/lib/python2.5/site-packages/django/db/models/query.py" in _update
  491.         return query.get_compiler(self.db).execute_sql(None)
File "/usr/lib/python2.5/site-packages/django/db/models/sql/compiler.py" in execute_sql
  869.         cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
File "/usr/lib/python2.5/site-packages/django/db/models/sql/compiler.py" in execute_sql
  735.         cursor.execute(sql, params)
File "/usr/lib/python2.5/site-packages/django/db/backends/util.py" in execute
  34.             return self.cursor.execute(sql, params)
File "/usr/lib/python2.5/site-packages/django/db/backends/mysql/base.py" in execute
  86.             return self.cursor.execute(query, args)
File "/var/lib/python-support/python2.5/MySQLdb/cursors.py" in execute
  168.         if not self._defer_warnings: self._warning_check()
File "/var/lib/python-support/python2.5/MySQLdb/cursors.py" in _warning_check
  82.                     warn(w[-1], self.Warning, 3)
File "/usr/lib/python2.5/warnings.py" in warn
  62.                   globals)
File "/usr/lib/python2.5/warnings.py" in warn_explicit
  102.         raise message

Exception Type: Warning at /admin/xivo_web/entity/3/
Exception Value: Column 'faxnumber' cannot be null

Issue Analytics

  • State:closed
  • Created 12 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
stefanfouliscommented, Sep 15, 2011

thanks for the pointer. I added it to the README.

I agree, there is actually no reason anymore to distinguish between None and "". Originally (I think) I used the two to distinguish between “not set” and “validation failed”. But the way the field is structured now, that is no longer needed.

I’ll re-open the ticket.

Thanks for reporting 😃

0reactions
edevilcommented, Jan 23, 2018

So I’m using version 2.0.0 of this module and seem to be having the same problem of this issue.

I have a model field defined like:

phone = PhoneNumberField(_('Phone'), blank=True)

However, when I submit a ModelForm without sending a value for “phone”, the form is valid but when I try to save the model I get:

django.db.utils.IntegrityError: null value in column "phone" violates not-null constraint

Is this a different problem?

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the difference between null=True and blank=True in ...
If a string-based field has null=True , that means it has two possible values for "no data": NULL , and the empty string....
Read more >
Blank, Coalesce, IsBlank, and IsEmpty functions in Power Apps
Tests whether a value is blank or a table contains no records, and provides ... In the context of the IsEmpty function, empty...
Read more >
How to select and highlight blank cells in Excel - Ablebits
Select and highlight empty cells with Go To Special · Filter and highlight blanks in a specific column · Highlight blank cells in...
Read more >
Best practices working with Django models in Python - SteelKiwi
Here we go: 1. Correct Model Naming. It is generally recommended to use singular nouns for model naming, for example: User , Post...
Read more >
NULL and Nothing - Qlik Community
How to convert empty fields or blank strings to NULL? ... True NULLs are cases when an existing record in the data model...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found