Ticket #247 (closed defect: fixed)

Opened 5 years ago

Last modified 4 years ago

Custom Model Fields throw exception durring migration

Reported by: erikcw Owned by: andrew
Priority: major Milestone: 0.7
Component: migrations Version: 0.6.1
Keywords: custom fields Cc:

Description

I'm using some custom model fields in a few of my applications. In this case, the custom field isn't even used in the app I'm migrating, but the 0.6.1 "freeze format" includes all the models in my project (which doesn't seem like a very good idea if you're attempting to keep loosely coupled apps)

Traceback (most recent call last):
  File "./manage.py", line 11, in <module>
    execute_manager(settings)
  File "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line 362, in execute_manager
    utility.execute()
  File "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line 303, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.5/site-packages/django/core/management/base.py", line 195, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib/python2.5/site-packages/django/core/management/base.py", line 222, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python2.5/site-packages/south/management/commands/migrate.py", line 91, in handle
    skip = skip,
  File "/usr/lib/python2.5/site-packages/south/migration.py", line 581, in migrate_app
    result = run_forwards(mapp, [mname], fake=fake, db_dry_run=db_dry_run, verbosity=verbosity)
  File "/usr/lib/python2.5/site-packages/south/migration.py", line 388, in run_forwards
    verbosity = verbosity,
  File "/usr/lib/python2.5/site-packages/south/migration.py", line 287, in run_migrations
    orm = klass.orm
  File "/usr/lib/python2.5/site-packages/south/orm.py", line 62, in __get__
    self.orm = FakeORM(*self._args)
  File "/usr/lib/python2.5/site-packages/south/orm.py", line 45, in FakeORM
    _orm_cache[args] = _FakeORM(*args)
  File "/usr/lib/python2.5/site-packages/south/orm.py", line 106, in __init__
    self.models[name] = self.make_model(app_name, model_name, data)
  File "/usr/lib/python2.5/site-packages/south/orm.py", line 282, in make_model
    field = self.eval_in_context(code, app, extra_imports)
  File "/usr/lib/python2.5/site-packages/south/orm.py", line 206, in eval_in_context
    raise ValueError("Cannot import the required field '%s'" % value)
ValueError: Cannot import the required field 'EncryptedCharField'

Change History

comment:1 Changed 5 years ago by andrew

  • Status changed from new to assigned
  • Milestone set to 0.6.2

Actually, the freeze format just includes the dependency closure of your app, which with more complex projects usually includes most of the other apps as well.

Have you read the wiki pages on making custom fields work? I suspect that'll work better, and not fail - currently, the parser is being used, and there's a reason we mostly replaced it with introspection.

comment:2 Changed 5 years ago by andrew

  • Milestone changed from 0.6.2 to 0.6.3

comment:3 Changed 5 years ago by guettli.south@…

Hi,

it took some time to understand the wiki page, but here is how I solved the above errors message (ValueError: Cannot import the required field '..custom DBField')

try:
    import south
    south.modelsinspector.add_introspection_rules(rules=[], patterns=[
            'djangotools\.dbfields\.',
            ])
except ImportError:
    pass

Of course, you need to change djangotools... to fit your path of your custom dbfields.

comment:4 Changed 5 years ago by andrew

  • Status changed from assigned to closed
  • Resolution set to fixed
  • Milestone changed from 0.6.3 to 0.7

This is no longer a problem in 0.7, so closing (we fixed up the custom models stuff to be more explicit).

comment:5 Changed 5 years ago by levity@…

Where are you supposed to put that "import south..." snippet?

comment:7 follow-up: ↓ 8 Changed 4 years ago by dan@…

I spent a good while trying to work this out and couldn't figure out the right syntax for this after looking through the docs and the examples. Are there any other examples that someone could point me to? Or help with debugging? Thanks

comment:8 in reply to: ↑ 7 Changed 4 years ago by andrew

Replying to dan@…:

I spent a good while trying to work this out and couldn't figure out the right syntax for this after looking through the docs and the examples. Are there any other examples that someone could point me to? Or help with debugging? Thanks

Come on IRC or post on the mailing list, and give some more detail on what you don't understand, and I should be able to help you.

Note: See TracTickets for help on using tickets.