ValueError: Cannot import the required field 'null_fields.Key'

42 views
Skip to first unread message

Ash

unread,
Dec 17, 2009, 4:05:16 AM12/17/09
to South Users
OK, yeah, I read the wiki page on extending the introspection and
still wasn't able to get it to work.

I've got the following simple subclass of some of the base Django
fields:

# File is eve.lib.null_fields
class Key(models.ForeignKey):
def __init__(self, *args, **kwargs):
kwargs['null'] = True
kwargs['blank'] = True
return super(Key, self).__init__(*args, **kwargs)

And I added the following to my main urls.py:

from south.modelsinspector import add_introspection_rules
add_introspection_rules(rules=[], patterns=["^eve\.lib\.null_fields"])

But yet I still get the error about not being able to import it.

What am I missing?

Oh, and please add a note to the wiki page suggesting that you add
this block to urls.py, as it took me a while to figure that out. The
docs arn't very user-centric.

Thomas Guettler

unread,
Dec 18, 2009, 4:33:13 AM12/18/09
to south...@googlegroups.com

Ash wrote:
> OK, yeah, I read the wiki page on extending the introspection and
> still wasn't able to get it to work.
>
> I've got the following simple subclass of some of the base Django
> fields:
>
> # File is eve.lib.null_fields
> class Key(models.ForeignKey):
> def __init__(self, *args, **kwargs):
> kwargs['null'] = True
> kwargs['blank'] = True
> return super(Key, self).__init__(*args, **kwargs)
>
> And I added the following to my main urls.py:
>
> from south.modelsinspector import add_introspection_rules
> add_introspection_rules(rules=[], patterns=["^eve\.lib\.null_fields"])
>
> But yet I still get the error about not being able to import it.

Did you recreate the migration file? Is the import statement at the top?

> Oh, and please add a note to the wiki page suggesting that you add
> this block to urls.py, as it took me a while to figure that out. The
> docs arn't very user-centric.

Yes, I think the documentation could be improved. Here are some things
that could be added:
- Simple example how to add a field that just subclasses from a django field.
- Where should the add_introspection_rules() call happen?

It would be better if the Exception would happen during creation of the migration
file, and not during executing it.

Thomas

--
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

Andrew Godwin

unread,
Dec 18, 2009, 1:44:06 PM12/18/09
to south...@googlegroups.com
You have to re-generate the affected migration for the change to take effect; it
changes what's written in the migration file (startmigration), not how it's
applied (migrate).

Andrew

> --
>
> You received this message because you are subscribed to the Google Groups
> "South Users" group. To post to this group, send email to
> south...@googlegroups.com. To unsubscribe from this group, send email
> to south-users...@googlegroups.com. For more options, visit this
> group at http://groups.google.com/group/south-users?hl=en.
>

Ash

unread,
Dec 21, 2009, 3:37:40 PM12/21/09
to South Users
Either I'm more lost than I thought, or you think I made it further
than I did.

I was able to run the migrate_to_south command for the app involved,
but this error is stopping me from making my migration.

I'm running: './migrate.py startmigration user skill_queue --auto',
and that's when it fails. So I don't have a migration file to
recreate. I think... (Nothing in user actually uses the null_field
fields, but they have ForeignKey relations to a different app that
isn't under South's control that does call null_fields.) It would also
be nice if South didn't demand to be able to import field types that
are not actually used in the app it's managing migrations for.

Andrew Godwin

unread,
Dec 22, 2009, 4:43:35 AM12/22/09
to south...@googlegroups.com
Apologies; import errors with introspection issues are nearly always
done during the migrate step. What's the exact error traceback?

Andrew

Ash

unread,
Dec 22, 2009, 4:02:04 PM12/22/09
to South Users
./manage.py startmigration user skill_queue --auto
Logging started.
Traceback (most recent call last):
File "./manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/
__init__.py", line 362, in execute_manager
utility.execute()
File "/usr/local/lib/python2.6/dist-packages/django/core/management/
__init__.py", line 303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/
base.py", line 195, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/
base.py", line 222, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.6/dist-packages/South-0.6.2-py2.6.egg/
south/management/commands/startmigration.py", line 237, in handle
last_orm = migrations[-1].orm
File "/usr/local/lib/python2.6/dist-packages/South-0.6.2-py2.6.egg/
south/orm.py", line 62, in __get__
self.orm = FakeORM(*self._args)
File "/usr/local/lib/python2.6/dist-packages/South-0.6.2-py2.6.egg/
south/orm.py", line 45, in FakeORM
_orm_cache[args] = _FakeORM(*args)
File "/usr/local/lib/python2.6/dist-packages/South-0.6.2-py2.6.egg/
south/orm.py", line 106, in __init__
self.models[name] = self.make_model(app_name, model_name, data)
File "/usr/local/lib/python2.6/dist-packages/South-0.6.2-py2.6.egg/
south/orm.py", line 282, in make_model
field = self.eval_in_context(code, app, extra_imports)
File "/usr/local/lib/python2.6/dist-packages/South-0.6.2-py2.6.egg/
south/orm.py", line 206, in eval_in_context
raise ValueError("Cannot import the required field '%s'" % value)
ValueError: Cannot import the required field 'null_fields.Key'

Ash

unread,
Jan 3, 2010, 9:56:19 PM1/3/10
to South Users
In the end, I went back to using deseb. I hope that in time South will
improve to the point where it's useful for me.
Reply all
Reply to author
Forward
0 new messages