Monday, November 2, 2015

Re: [1.8] Odd error on makemigrations when moving model to another application

On 3/11/2015 9:55 AM, Alex Heyden wrote:
> I tried putting the model back in its original module with some much
> smaller changes, but I'm getting the same error. The error is nonsense
> in the current context.
>
> Is there some intermediate state saved somewhere when you try to run
> makemigrations?

Not as far as I can tell. I too have had difficulty moving models
between apps. It is in my too-hard basket for the moment. However ...

When I try again I'll create the model-to-be-moved in its new app and
get that working properly. I would definitely do a makemigration but
edit the migration file prior to migrating to use a forwards_func()
method to get the data across and entrenched in its proper relations
with other models on creation. Finally, when all is working I'd bravely
drop the old model in a separate migration.

hth

Mike

>
> On Mon, Nov 2, 2015 at 4:34 PM, Alex Heyden <mindsbreath@gmail.com
> <mailto:mindsbreath@gmail.com>> wrote:
>
> Traceback first:
>
> ./manage.py makemigrations
> Traceback (most recent call last):
> Â File "./manage.py", line 10, in <module>
> Â Â execute_from_command_line(sys.argv)
> Â File
> "/home/me/.virtualenvs/fluent/local/lib/python2.7/site-packages/django/core/management/__init__.py",
> line 351, in execute_from_command_line
> Â Â utility.execute()
> Â File
> "/home/me/.virtualenvs/fluent/local/lib/python2.7/site-packages/django/core/management/__init__.py",
> line 343, in execute
> Â Â self.fetch_command(subcommand).run_from_argv(self.argv)
> Â File
> "/home/me/.virtualenvs/fluent/local/lib/python2.7/site-packages/django/core/management/base.py",
> line 394, in run_from_argv
> Â Â self.execute(*args, **cmd_options)
> Â File
> "/home/me/.virtualenvs/fluent/local/lib/python2.7/site-packages/django/core/management/base.py",
> line 445, in execute
> Â Â output = self.handle(*args, **options)
> Â File
> "/home/me/.virtualenvs/fluent/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py",
> line 125, in handle
> Â Â migration_name=self.migration_name,
> Â File
> "/home/me/.virtualenvs/fluent/local/lib/python2.7/site-packages/django/db/migrations/autodetector.py",
> line 43, in changes
> Â Â changes = self._detect_changes(convert_apps, graph)
> Â File
> "/home/me/.virtualenvs/fluent/local/lib/python2.7/site-packages/django/db/migrations/autodetector.py",
> line 110, in _detect_changes
> Â Â self.old_apps = self.from_state.concrete_apps
> Â File
> "/home/me/.virtualenvs/fluent/local/lib/python2.7/site-packages/django/db/migrations/state.py",
> line 170, in concrete_apps
> Â Â self.apps = StateApps(self.real_apps, self.models,
> ignore_swappable=True)
> Â File
> "/home/me/.virtualenvs/fluent/local/lib/python2.7/site-packages/django/db/migrations/state.py",
> line 248, in __init__
> Â Â raise ValueError(msg.format(field=operations[0][1],
> model=lookup_model))
> ValueError: Lookup failed for model referenced by field
> sdd.Documentation.opportunity: sdd.......governance.models.Opportunity
>
> Needless to say, sdd.......governance.models.Opportunity is not a
> valid path to anything.
>
> The Opportunity model was moved from the sdd application to the
> governance application. Documentation has a foreign key to
> Opportunity. The Python itself is correct. It used to be a direct
> reference to the class in the module, now it's an imported
> reference. All of the foreign keys are handled in the same way.
> Nothing is done by string.
>
> I'm ok with a one-off solution for the migration, but I'm more
> interested in /why/Â the model path is so far off and what I might
> have done to cause it.
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to django-users+unsubscribe@googlegroups.com
> <mailto:django-users+unsubscribe@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto:django-users@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d5d6fcf9-8b76-4448-81fb-e38765b66d03%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/d5d6fcf9-8b76-4448-81fb-e38765b66d03%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscribe@googlegroups.com
> <mailto:django-users+unsubscribe@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto:django-users@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CA%2Bv0ZYWOTbagf0NUYy9%2BrCwQNPjaDJzdZAaOgCkm7ox7%2BXY60A%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CA%2Bv0ZYWOTbagf0NUYy9%2BrCwQNPjaDJzdZAaOgCkm7ox7%2BXY60A%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/563840E7.7060103%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment