Repository: django-wiki/django-wiki

Issue:
(1048, "Column 'revision_number' cannot be null") Wiki_images plugin
This is my first git-issue post so go easy
**dev computer: Django=2.1.7, Python 3.7.3 
Server: Django=2.1.7       Python 3.5.3 
Tried both latest and stable versions of Django-wiki**
When trying to upload images via the Django admin, I'm faced with the error
`(1048,' "Column 'revision_number' cannot be null")`
 After doing some digging and trial an error I was able to hack together a quick fix for my app. I did this by adding "default=1" to line 285 of wiki/models/article.py(+/- 2 lines)

`revision_number = models.IntegerField(
        editable=False,verbose_name=_('revision number'),default=1)`

By also adding an if statement in the rendering of the string for the reversion number in I was able to get around this error. This piece was in wiki/plugins/images/models.py  lines 103

Old:
```
def __str__(self):
        return gettext('Image Revision: %d') % self.revision_number`
```

temp fix:
```
def __str__(self):
        if self.revision_number:
            return gettext('Image Revision: %s') % self.revision_number
        else:
            return "None"
```

From what i can tell the BaseRevisionMixin class in article.py creates a new object for the new image being uploaded but doesnt assign it a revision number.
i tried playing around with the ImageForm in Images/admin.py
but was unable to correctly come up with a way to force create a revison following the code from the attachment plugin form.py but was unable to come up with a soultion.

Full traceback from server:

```
Environment:
Request Method: POST
Request URL: ***/admin/wiki_images/image/add/
Django Version: 2.1.7
Python Version: 3.5.3
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites.apps.SitesConfig',
 'django.contrib.humanize.apps.HumanizeConfig',
 'django_nyt.apps.DjangoNytConfig',
 'mptt',
 'sekizai',
 'sorl.thumbnail',
 'wiki.apps.WikiConfig',
 'wiki.plugins.attachments.apps.AttachmentsConfig',
 'wiki.plugins.notifications.apps.NotificationsConfig',
 'wiki.plugins.images.apps.ImagesConfig',
 'wiki.plugins.macros.apps.MacrosConfig',
 'lifeafter',
 'django.contrib.sitemaps']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/db/backends/mysql/base.py" in execute
  71.             return self.cursor.execute(query, args)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/MySQLdb/cursors.py" in execute
  250.             self.errorhandler(self, exc, value)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/MySQLdb/connections.py" in defaulterrorhandler
  50.         raise errorvalue
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/MySQLdb/cursors.py" in execute
  247.             res = self._query(query)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/MySQLdb/cursors.py" in _query
  411.         rowcount = self._do_query(q)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/MySQLdb/cursors.py" in _do_query
374.         db.query(q)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/MySQLdb/connections.py" in query
277.             _mysql.connection.query(self, query)
During handling of the above exception ((1048, "Column 'revision_number' cannot be null")), another exception occurred:
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
34.             response = get_response(request)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
126.                 response = self.process_exception_by_middleware(e, request)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
  124.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/contrib/admin/options.py" in wrapper
  604.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/contrib/admin/sites.py" in inner
  223.             return view(request, *args, **kwargs)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/contrib/admin/options.py" in add_view
  1637.         return self.changeform_view(request, None, form_url, extra_context)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/utils/decorators.py" in _wrapper
  45.         return bound_method(*args, **kwargs)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/contrib/admin/options.py" in changeform_view
  1525.             return self._changeform_view(request, object_id, form_url, extra_context)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/contrib/admin/options.py" in _changeform_view
  1565.                 self.save_related(request, form, formsets, not add)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/contrib/admin/options.py" in save_related
  1119.             self.save_formset(request, form, formset, change=change)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/contrib/admin/options.py" in save_formset
  1107.         formset.save()
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/forms/models.py" in save
  669.         return self.save_existing_objects(commit) + self.save_new_objects(commit)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/forms/models.py" in save_new_objects
  803.             self.new_objects.append(self.save_new(form, commit=commit))
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/forms/models.py" in save_new
  949.             obj.save()
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/db/models/base.py" in save
  718.                        force_update=force_update, update_fields=update_fields)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/db/models/base.py" in save_base
  747.                 self._save_parents(cls, using, update_fields)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/db/models/base.py" in _save_parents
  772.             self._save_table(cls=parent, using=using, update_fields=update_fields)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/db/models/base.py" in _save_table
  831.             result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/db/models/base.py" in _do_insert
  869.                                using=using, raw=raw)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/db/models/manager.py" in manager_method
  82.                 return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/db/models/query.py" in _insert
  1136.         return query.get_compiler(using=using).execute_sql(return_id)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/db/models/sql/compiler.py" in execute_sql
  1289.                 cursor.execute(sql, params)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/db/backends/utils.py" in execute
  100.             return super().execute(sql, params)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/db/backends/utils.py" in execute
  68.         return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/db/backends/utils.py" in _execute_with_wrappers
  77.         return executor(sql, params, many, context)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/db/backends/utils.py" in _execute
  85.                 return self.cursor.execute(sql, params)
File "/home/*user*/*project*/wiki/lib/python3.5/site-packages/django/db/backends/mysql/base.py" in execute
  76.                 raise utils.IntegrityError(*tuple(e.args))
Exception Type: IntegrityError at /admin/wiki_images/image/add/
Exception Value: (1048, "Column 'revision_number' cannot be null")
```


Discussion:

Resolving patch:
diff --git a/src/wiki/__init__.py b/src/wiki/__init__.py
--- a/src/wiki/__init__.py
+++ b/src/wiki/__init__.py
@@ -19,5 +19,5 @@
 
 default_app_config = 'wiki.apps.WikiConfig'
 
-VERSION = (0, 4, 4, 'final', 0)
+VERSION = (0, 4, 5, 'final', 0)
 __version__ = get_version(VERSION)
diff --git a/src/wiki/plugins/images/models.py b/src/wiki/plugins/images/models.py
--- a/src/wiki/plugins/images/models.py
+++ b/src/wiki/plugins/images/models.py
@@ -101,7 +101,10 @@ class Meta:
         ordering = ('-created',)
 
     def __str__(self):
-        return gettext('Image Revision: %d') % self.revision_number
+        if self.revision_number:
+            return gettext('Image Revision: %d') % self.revision_number
+        else:
+            return gettext('Current revision not set!!')
 
 
 def on_image_revision_delete(instance, *args, **kwargs):


Test patch: