berinhard / model_mommy

No longer maintained, please migrate to model_bakery
http://model-bakery.readthedocs.org/
Other
903 stars 141 forks source link

Index row too large? (Postgres) #238

Closed mamigot closed 9 years ago

mamigot commented 9 years ago

I'm getting an error when model_mommy saves to my Postgres database. This is the traceback:

Traceback (most recent call last):
    m = mommy.make('my_app.MyModel')
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/model_mommy/mommy.py", line 79, in make
    return mommy.make(**attrs)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/model_mommy/mommy.py", line 262, in make
    return self._make(commit=True, **attrs)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/model_mommy/mommy.py", line 312, in _make
    model_attrs[field.name] = self.generate_value(field)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/model_mommy/mommy.py", line 429, in generate_value
    return generator(**generator_attrs)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/model_mommy/mommy.py", line 79, in make
    return mommy.make(**attrs)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/model_mommy/mommy.py", line 262, in make
    return self._make(commit=True, **attrs)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/model_mommy/mommy.py", line 312, in _make
    model_attrs[field.name] = self.generate_value(field)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/model_mommy/mommy.py", line 429, in generate_value
    return generator(**generator_attrs)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/model_mommy/mommy.py", line 79, in make
    return mommy.make(**attrs)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/model_mommy/mommy.py", line 262, in make
    return self._make(commit=True, **attrs)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/model_mommy/mommy.py", line 321, in _make
    return self.instance(model_attrs, _commit=commit)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/model_mommy/mommy.py", line 340, in instance
    instance.save()
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/models/base.py", line 710, in save
    force_update=force_update, update_fields=update_fields)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/models/base.py", line 738, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/models/base.py", line 822, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/models/base.py", line 861, in _do_insert
    using=using, raw=raw)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/models/manager.py", line 127, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/models/query.py", line 920, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 974, in execute_sql
    cursor.execute(sql, params)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/utils.py", line 97, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/utils/six.py", line 658, in reraise
    raise value.with_traceback(tb)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
django.db.utils.OperationalError: index row requires 8208 bytes, maximum size is 8191

Another model was instantiated using mommy without a problem --this is just one with a few more fields.

I have modified MAX_LENGTH and MAX_INT in generators.py but that hasn't fixed it. Please let me know if there is another parameter I should change though, and thank you!

vandersonmota commented 9 years ago

Hi @miguel5, could you provide more details? Is this happening with any model? Which version are you using?

mamigot commented 9 years ago

Thanks for the quick response, @vandersonmota ! This doesn't happen with every model (it works with some of them), but with this one specifically:

class MyModel(models.Model):
    one= models.CharField(max_length=4096, blank=True, null=True)
    two = models.TextField(blank=True, null=True)
    three = models.AutoField(primary_key=True)
    attributes = JsonBField(null=True, blank=True, default={})

Could the problem be the JSON field? I'm importing it as from django_pgjson.fields import JsonBField, and using django-pgjson==0.2.3.

And I'm using model-mommy==1.2.4.

Thank you!

vandersonmota commented 9 years ago

@miguel5 it looks like an error caused by JsonBField. Did you tried registering a custom generator for it? http://model-mommy.readthedocs.org/en/latest/how_mommy_behaves.html#custom-fields

mamigot commented 9 years ago

Sorry @vandersonmota, I hadn't come across and therefore did not try the custom generators. Will do as soon as I get a chance! Thank you!