Hi there,
I've been using MySQL with Django, and haven't been able to solve this error for some time. I use South for migrations.
Essentially, I don't want the field 'link' in my blog model - I just want to delete it totally. I've tried schemamigration and even deleting all migration files and re-converting the blog app to south from scratch, after backwarding it to zero. There's no mention of link in models.py so I don't know why it persists. Checking sqlall, it is not a column in the table either (empty or not).
Here is the error:
DatabaseError at /admin/blog/post/add/
Field 'link' doesn't have a default value
Request Method: POST
Request URL: http://nuovovesuvio.pythonanywhere.com/admin/blog/post/add/
Django Version: 1.6.6
Exception Type: DatabaseError
Exception Value:
Field 'link' doesn't have a default value
Exception Location: /home/NuovoVesuvio/.local/lib/python3.3/site-packages/mysql/connector/cursor.py in _fetch_warnings, line 750
Python Executable: /usr/local/bin/uwsgi
Python Version: 3.3.5
Python Path:
['/var/www',
'.',
'',
'/home/NuovoVesuvio/.local/lib/python3.3/site-packages',
'/usr/local/lib/python3.3/dist-packages/setuptools-7.0-py3.3.egg',
'/usr/local/lib/python3.3/dist-packages/matplotlib-1.3.1-py3.3-linux-x86_64.egg',
'/usr/local/lib/python3.3/dist-packages/certifi-14.05.14-py3.3.egg',
'/var/www',
'/usr/lib/python3.3',
'/usr/lib/python3.3/plat-linux',
'/usr/lib/python3.3/lib-dynload',
'/usr/local/lib/python3.3/dist-packages',
'/usr/lib/python3/dist-packages',
'/home/NuovoVesuvio/DareToThink']
Server time: Mon, 17 Nov 2014 17:48:38 +0000
Traceback Switch to copy-and-paste view
/usr/local/lib/python3.3/dist-packages/django/core/handlers/base.py in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs) ...
▶ Local vars
/usr/local/lib/python3.3/dist-packages/django/contrib/admin/options.py in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs) ...
▶ Local vars
/usr/local/lib/python3.3/dist-packages/django/utils/decorators.py in _wrapped_view
response = view_func(request, *args, **kwargs) ...
▶ Local vars
/usr/local/lib/python3.3/dist-packages/django/views/decorators/cache.py in _wrapped_view_func
response = view_func(request, *args, **kwargs) ...
▶ Local vars
/usr/local/lib/python3.3/dist-packages/django/contrib/admin/sites.py in inner
return view(request, *args, **kwargs) ...
▶ Local vars
/usr/local/lib/python3.3/dist-packages/django/utils/decorators.py in _wrapper
return bound_func(*args, **kwargs) ...
▶ Local vars
/usr/local/lib/python3.3/dist-packages/django/utils/decorators.py in _wrapped_view
response = view_func(request, *args, **kwargs) ...
▶ Local vars
/usr/local/lib/python3.3/dist-packages/django/utils/decorators.py in bound_func
return func(self, *args2, **kwargs2) ...
▶ Local vars
/usr/local/lib/python3.3/dist-packages/django/db/transaction.py in inner
return func(*args, **kwargs) ...
▶ Local vars
/usr/local/lib/python3.3/dist-packages/django/contrib/admin/options.py in add_view
self.save_model(request, new_object, form, False) ...
▶ Local vars
/usr/local/lib/python3.3/dist-packages/django/contrib/admin/options.py in save_model
obj.save() ...
▶ Local vars
/usr/local/lib/python3.3/dist-packages/django/db/models/base.py in save
force_update=force_update, update_fields=update_fields) ...
▶ Local vars
/usr/local/lib/python3.3/dist-packages/django/db/models/base.py in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields) ...
▶ Local vars
/usr/local/lib/python3.3/dist-packages/django/db/models/base.py in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw) ...
▶ Local vars
/usr/local/lib/python3.3/dist-packages/django/db/models/base.py in _do_insert
using=using, raw=raw) ...
▶ Local vars
/usr/local/lib/python3.3/dist-packages/django/db/models/manager.py in _insert
return insert_query(self.model, objs, fields, **kwargs) ...
▶ Local vars
/usr/local/lib/python3.3/dist-packages/django/db/models/query.py in insert_query
return query.get_compiler(using=using).execute_sql(return_id) ...
▶ Local vars
/usr/local/lib/python3.3/dist-packages/django/db/models/sql/compiler.py in execute_sql
cursor.execute(sql, params) ...
▶ Local vars
/usr/local/lib/python3.3/dist-packages/django/db/backends/util.py in execute
return super(CursorDebugWrapper, self).execute(sql, params) ...
▶ Local vars
/usr/local/lib/python3.3/dist-packages/django/db/backends/util.py in execute
return self.cursor.execute(sql, params) ...
▶ Local vars
/home/NuovoVesuvio/.local/lib/python3.3/site-packages/mysql/connector/django/base.py in execute
return self._execute_wrapper(self.cursor.execute, query, args) ...
▶ Local vars
/home/NuovoVesuvio/.local/lib/python3.3/site-packages/mysql/connector/django/base.py in _execute_wrapper
utils.DatabaseError(err.msg), sys.exc_info()[2]) ...
▶ Local vars
/usr/local/lib/python3.3/dist-packages/django/utils/six.py in reraise
raise value.with_traceback(tb) ...
▶ Local vars
/home/NuovoVesuvio/.local/lib/python3.3/site-packages/mysql/connector/django/base.py in _execute_wrapper
return method(query, args) ...
▶ Local vars
/home/NuovoVesuvio/.local/lib/python3.3/site-packages/mysql/connector/cursor.py in execute
self._handle_result(self._connection.cmd_query(stmt)) ...
▶ Local vars
/home/NuovoVesuvio/.local/lib/python3.3/site-packages/mysql/connector/cursor.py in _handle_result
self._handle_noresultset(result) ...
▶ Local vars
/home/NuovoVesuvio/.local/lib/python3.3/site-packages/mysql/connector/cursor.py in _handle_noresultset
self._warnings = self._fetch_warnings() ...
▶ Local vars
/home/NuovoVesuvio/.local/lib/python3.3/site-packages/mysql/connector/cursor.py in _fetch_warnings
raise errors.get_mysql_exception(res[0][1], res[0][2]) ...
▶ Local vars
Request information
GET
No GET data
POST
Variable Value
description
'thistest'
published
'on'
_save
'Save'
slug
'thistest'
content
'thistestthistestthistestthistestthistestthistest'
author
'1'
csrfmiddlewaretoken
'LRuAxBqEwVoBxmwYZCqMSvfLUynEEGpr'
title
'thistest'
FILES
No FILES data
COOKIES
Variable Value
BCSI-CS-997ed7499a2363c4
'2'
csrftoken
'LRuAxBqEwVoBxmwYZCqMSvfLUynEEGpr'
sessionid
'4ia1y35iy6lr1dsi3iqlem7p2s6065qq'
META
Variable Value
wsgi.run_once
False
HTTP_X_BLUECOAT_VIA
'af1da519007b80b7'
PATH_INFO
'/admin/blog/post/add/'
wsgi.errors
<uwsgi_file__bin_user_wsgi_wrapper.ErrorLogFile object at 0x7faac4e6ff10>
REMOTE_PORT
'43096'
HTTP_HOST
'nuovovesuvio.pythonanywhere.com'
wsgi.multithread
False
HTTP_ACCEPT_ENCODING
'gzip,deflate'
REMOTE_ADDR
'10.73.141.31'
HTTP_X_REAL_IP
'212.119.7.106'
HTTP_USER_AGENT
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36'
HTTP_REFERER
'http://nuovovesuvio.pythonanywhere.com/admin/blog/post/add/'
SCRIPT_NAME
''
REQUEST_URI
'/admin/blog/post/add/'
HTTP_X_FORWARDED_FOR
'212.119.7.106'
wsgi.file_wrapper
''
CONTENT_LENGTH
'917'
HTTP_COOKIE
'BCSI-CS-997ed7499a2363c4=2; sessionid=4ia1y35iy6lr1dsi3iqlem7p2s6065qq; csrftoken=LRuAxBqEwVoBxmwYZCqMSvfLUynEEGpr'
CSRF_COOKIE
'LRuAxBqEwVoBxmwYZCqMSvfLUynEEGpr'
HTTP_CONTENT_TYPE
'multipart/form-data; boundary=----WebKitFormBoundaryYu53yqA9xWIq3VAX'
SERVER_PORT
'80'
DOCUMENT_ROOT
'/usr/local/openresty/nginx/html'
wsgi.url_scheme
'http'
HTTP_ORIGIN
'http://nuovovesuvio.pythonanywhere.com'
wsgi.multiprocess
True
HTTP_CONTENT_LENGTH
'917'
REQUEST_METHOD
'POST'
CONTENT_TYPE
'multipart/form-data; boundary=----WebKitFormBoundaryYu53yqA9xWIq3VAX'
HTTP_CONNECTION
'close'
QUERY_STRING
''
uwsgi.node
b'harry-liveweb2'
wsgi.version
(1, 0)
SERVER_PROTOCOL
'HTTP/1.1'
HTTP_ACCEPT
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
wsgi.input
<uwsgi._Input object at 0x7faac3fc4828>
HTTP_ACCEPT_LANGUAGE
'en-GB,en-US;q=0.8,en;q=0.6'
uwsgi.version
b'2.0.5.1'
HTTP_CACHE_CONTROL
'max-age=0'
SERVER_NAME
'nuovovesuvio.pythonanywhere.com'
and here is my models.py:
from django.db import models
from django.core.urlresolvers import reverse
#from django.contrib.auth.models import User
from userprofile.models import UserProfile
class Post(models.Model):
title = models.CharField(max_length=255)
slug = models.SlugField(unique=True, max_length=255)
description = models.CharField(max_length=255)
content = models.TextField()
published = models.BooleanField(default=True)
created = models.DateTimeField(auto_now_add=True)
#author = models.ForeignKey(User)
author = models.ForeignKey(UserProfile)
#link = models.CharField(max_length=255)
#link_description = models.CharField(max_length=255)
class Meta:
ordering = ['-created']
def __unicode__(self):
return u'%s' % self.title
def get_absolute_url(self):
return reverse('blog.views.blog_getpost', args=[self.slug])
As you can see, if I include the link and link_description fields with NOT NULL, the app works, but I don't want them at all in the model.
Thanks for your help!!