Skip to content

Using FileBrowseField with django 1.9 + mezzanine 4.1.0 #81

@frague59

Description

@frague59

Hi,

I'm trying to use a model FileBrowseField with django 1.9 + mezzanine 4.1.0.
I'm trying to create an abstract model used by various items :

class Illustrated(models.Model):
    """
    Model mixin to add an *illustration* to an item
    """

    class Meta:
        abstract = True

    #: Illustration file
    illustration = FileBrowseField(verbose_name=_('Illustration'),
                                   null=True, blank=True,
                                   extensions=ILLUSTRATION_FILE_TYPES,
                                   directory='images'
                                   )

    #: Illustration credit short text (255 max)
    illustration_credit = models.CharField(max_length=255, verbose_name=_('image credit'), default=_('rights reserved'),
                                           null=True, blank=True)

where ILLUSTRATION_FILE_TYPES is a list of extensions, and then I create a migration

$ ./manage.py makemigrations

When actualy migrating I've an error :

$ ./manage.py migrate
Operations to perform:
  Apply all migrations: intrapubs
Running migrations:
  Rendering model states... DONE
  Applying intrapubs.0001_initial...Traceback (most recent call last):
  File "./manage.py", line 14, in <module>
    execute_from_command_line(sys.argv)
  File "/home/fguerin/Boulot/workspace/django/intranet_clear/virtualenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/home/fguerin/Boulot/workspace/django/intranet_clear/virtualenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/fguerin/Boulot/workspace/django/intranet_clear/virtualenv/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/fguerin/Boulot/workspace/django/intranet_clear/virtualenv/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/home/fguerin/Boulot/workspace/django/intranet_clear/virtualenv/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 200, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/home/fguerin/Boulot/workspace/django/intranet_clear/virtualenv/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 92, in migrate
    self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/home/fguerin/Boulot/workspace/django/intranet_clear/virtualenv/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/home/fguerin/Boulot/workspace/django/intranet_clear/virtualenv/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 198, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/fguerin/Boulot/workspace/django/intranet_clear/virtualenv/local/lib/python2.7/site-packages/django/db/migrations/migration.py", line 123, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/home/fguerin/Boulot/workspace/django/intranet_clear/virtualenv/local/lib/python2.7/site-packages/django/db/migrations/operations/models.py", line 59, in database_forwards
    schema_editor.create_model(model)
  File "/home/fguerin/Boulot/workspace/django/intranet_clear/virtualenv/local/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 284, in create_model
    self.execute(sql, params or None)
  File "/home/fguerin/Boulot/workspace/django/intranet_clear/virtualenv/local/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 110, in execute
    cursor.execute(sql, params)
  File "/home/fguerin/Boulot/workspace/django/intranet_clear/virtualenv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/fguerin/Boulot/workspace/django/intranet_clear/virtualenv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/fguerin/Boulot/workspace/django/intranet_clear/virtualenv/local/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/fguerin/Boulot/workspace/django/intranet_clear/virtualenv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)
  File "/home/fguerin/Boulot/workspace/django/intranet_clear/virtualenv/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 321, in execute
    return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: near "None": syntax error

When I debugs, I can see that the datble creation attemps to create a VARCHAR columns for the illustration field with a length of "None", which can"t work :

CREATE TABLE "intrapubs_event"
    ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
     "keywords_string" varchar(500) NOT NULL,
     "title" varchar(500) NOT NULL,
     "slug" varchar(2000) NULL,
     "_meta_title" varchar(500) NULL,
     "description" text NOT NULL,
     "gen_description" bool NOT NULL,
     "created" datetime NULL,
     "updated" datetime NULL,
     "status" integer NOT NULL,
     "publish_date" datetime NULL,
     "expiry_date" datetime NULL,
     "short_url" varchar(200) NULL,
     "in_sitemap" bool NOT NULL,
     **"illustration" varchar(None) NULL,**
     "illustration_credit" varchar(255) NULL,
     "content" text NOT NULL,
     "contact_url" varchar(200) NULL,
     "contact_email" varchar(254) NULL,
     "contact_phone" varchar(50) NULL,
     "date_from" datetime NOT NULL,
     "date_to" datetime NULL)

I've seen too that in the code, there is a reference to a oldforms module, which does not seem to be imported in the fields module.

Thanks for your help !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions