richardbarran / django-photologue

A customizable plug-in photo gallery management application for the Django web framework.
BSD 3-Clause "New" or "Revised" License
675 stars 239 forks source link

IntegrityError when saving #164

Closed dco5 closed 7 years ago

dco5 commented 7 years ago

Hello, I am getting: null value in column "id" violates not-null constraint DETAIL: Failing row contains (null, 182, 1).

I have not been able to figure out why this happening? Django is suppose to take care of the ID, so I dunno why it would be NULL, does photologue changes how ID is generated?

I am using cairocffi==0.7.2 CairoSVG==1.0.22 cffi==1.7.0 chardet==2.3.0 cssselect==0.9.2 Cython==0.24.1 Django==1.8.13 django-braces==1.9.0 django-contrib-comments==1.7.1 django-debug-toolbar==1.4 django-filebrowser-no-grappelli==3.6.2 django-photologue==3.5.1 django-recaptcha2==1.0.0 django-sortedm2m==1.3.2 django-widget-tweaks==1.4.1 ExifRead==2.1.2 gunicorn==19.6.0 html5lib==0.999999999 lxml==3.6.1 MySQL-python==1.2.5 Pillow==3.2.0 psycopg2==2.6.1 pycparser==2.14 Pyphen==0.9.4 requests==2.10.0 six==1.10.0 sorl-thumbnail==12.3 sqlparse==0.1.19 ssh-import-id==5.5 tinycss==0.3 unicodecsv==0.14.1 Unipath==1.1 urllib3==1.16 WeasyPrint==0.30 webencodings==0.5

richardbarran commented 7 years ago

Hello, The "id" column should be handled automatically by Django - Photologue does not modify this. Which table is causing the error message?

dco5 commented 7 years ago

This is the only SQL I could find in the Traceback u'INSERT INTO "photologue_photo_sites" ("photo_id", "site_id") VALUES (%s, %s)' u'INSERT INTO "photologue_photo_sites" ("photo_id", "site_id") VALUES (181, 1)'

I maybe it has something to do with photologue_photo_sites table?

dco5 commented 7 years ago

Traceback: File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response

  1. response = wrapped_callback(request, _callback_args, *_callback_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in wrapper
  2. return self.admin_site.admin_view(view)(_args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
  3. response = view_func(request, _args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
  4. response = view_func(request, _args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in inner
  5. return view(request, _args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in add_view
  6. return self.changeform_view(request, None, form_url, extra_context) File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapper
  7. return bound_func(_args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
  8. response = view_func(request, _args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in bound_func
  9. return func.get(self, type(self))(_args2, *_kwargs2) File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in inner
  10. return func(_args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in changeform_view
  11. self.save_model(request, new_object, form, not add) File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in save_model
  12. obj.save() File "/usr/local/lib/python2.7/dist-packages/photologue/models.py" in save
  13. super(Photo, self).save(_args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/photologue/models.py" in save
  14. super(ImageModel, self).save(_args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py" in save
  15. force_update=force_update, update_fields=update_fields) File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py" in save_base
  16. update_fields=update_fields, raw=raw, using=using) File "/usr/local/lib/python2.7/dist-packages/django/dispatch/dispatcher.py" in send
  17. response = receiver(signal=self, sender=sender, **named) File "/usr/local/lib/python2.7/dist-packages/photologue/models.py" in add_default_site
  18. instance.sites.add(Site.objects.get_current()) File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.py" in add
  19. self._add_items(self.source_field_name, self.target_field_name, *objs) File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.py" in _add_items
  20. for obj_id in new_ids File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in bulk_create
  21. self._batched_insert(objs_without_pk, fields, batch_size) File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in _batched_insert
  22. using=self.db) File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py" in manager_method
  23. return getattr(self.get_queryset(), name)(_args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in _insert
  24. return query.get_compiler(using=using).execute_sql(return_id) File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py" in execute_sql
  25. cursor.execute(sql, params) File "/usr/local/lib/python2.7/dist-packages/debug_toolbar/panels/sql/tracking.py" in execute
  26. return self._record(self.cursor.execute, sql, params) File "/usr/local/lib/python2.7/dist-packages/debug_toolbar/panels/sql/tracking.py" in _record
  27. return method(sql, params) File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py" in execute
  28. return super(CursorDebugWrapper, self).execute(sql, params) File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py" in execute
  29. return self.cursor.execute(sql, params) File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py" in exit
  30. six.reraise(dj_exc_type, dj_exc_value, traceback) File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py" in execute
  31. return self.cursor.execute(sql, params)

Exception Type: IntegrityError at /admin/photologue/photo/add/ Exception Value: null value in column "id" violates not-null constraint DETAIL: Failing row contains (null, 182, 1).

richardbarran commented 7 years ago

Thank you for the extra information - it's very strange. There's on insert into table photologue_photo_sites; the id column value is not specified. On my system that does not matter: I am using a PostgreSQL database, and the ID column is defined to auto-insert a sequence number. Are you using MySQL? I am not familiar with that database - can you check if for table 'photologue_photo_sites' the ID column is automatically populated?

dco5 commented 7 years ago

I am using Postgresql, so that is very weird then. I will check the table definition and see what it says.

richardbarran commented 7 years ago

Hi @dco5 - did you manage to resolve this bug?