Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't handle FK and ManyToMany relationships #3

Open
oliver-zhou opened this issue Apr 12, 2018 · 6 comments
Open

Doesn't handle FK and ManyToMany relationships #3

oliver-zhou opened this issue Apr 12, 2018 · 6 comments

Comments

@oliver-zhou
Copy link

When trying to run this on a migration of a model from one app to another that I've been attempting, this bombs out handling a ManyToOne relationship


File "manage.py", line 23, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/Users/oliver/src/h_mvp_backend/candidates/management/commands/movemodel.py", line 97, in handle
    self.write_migration_files(changes)
  File "/Users/oliver/src/h_mvp_backend/candidates/management/commands/movemodel.py", line 216, in write_migration_files
    migration_string = writer.as_string()
  File "/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/django/db/migrations/writer.py", line 163, in as_string
    operation_string, operation_imports = OperationWriter(operation).serialize()
  File "/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/django/db/migrations/writer.py", line 120, in serialize
    _write(arg_name, arg_value)
  File "/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/django/db/migrations/writer.py", line 84, in _write
    arg_string, arg_imports = MigrationWriter.serialize(_arg_value)
  File "/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/django/db/migrations/writer.py", line 293, in serialize
    return serializer_factory(value).serialize()
  File "/Users/oliver/.virtualenvs/hirevisor_api/lib/python2.7/site-packages/django/db/migrations/serializer.py", line 396, in serializer_factory
    "topics/migrations/#migration-serializing" % (value, get_docs_version())
ValueError: Cannot serialize: <ManyToOneRel: jobs.job>
There are some values Django cannot serialize into migration files.
For more, see https://docs.djangoproject.com/en/1.11/topics/migrations/#migration-serializing
@oliver-zhou oliver-zhou changed the title Doesn't handle ManyToOne relationships Doesn't handle FK and ManyToMany relationships Apr 12, 2018
@alexei
Copy link
Owner

alexei commented Apr 12, 2018

ForeignKeys should work fine. I didn't check with ManyToManyFields and OneToOneFields though.

@oliver-zhou
Copy link
Author

Will try to reproduce on a simplified model in a bit -> but this is occurring when there are a couple of fk relationships and a few manytomany relationships

@TheBlusky
Copy link

Same issue here:

Traceback (most recent call last):
  File "/opt/project/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
    output = self.handle(*args, **options)
  File "/opt/project/dashboardapi/management/commands/movemodel.py", line 97, in handle
    self.write_migration_files(changes)
  File "/opt/project/dashboardapi/management/commands/movemodel.py", line 216, in write_migration_files
    migration_string = writer.as_string()
  File "/usr/local/lib/python3.6/site-packages/django/db/migrations/writer.py", line 151, in as_string
    operation_string, operation_imports = OperationWriter(operation).serialize()
  File "/usr/local/lib/python3.6/site-packages/django/db/migrations/writer.py", line 110, in serialize
    _write(arg_name, arg_value)
  File "/usr/local/lib/python3.6/site-packages/django/db/migrations/writer.py", line 74, in _write
    arg_string, arg_imports = MigrationWriter.serialize(_arg_value)
  File "/usr/local/lib/python3.6/site-packages/django/db/migrations/writer.py", line 279, in serialize
    return serializer_factory(value).serialize()
  File "/usr/local/lib/python3.6/site-packages/django/db/migrations/serializer.py", line 370, in serializer_factory
    "topics/migrations/#migration-serializing" % (value, get_docs_version())
ValueError: Cannot serialize: <ManyToOneRel: hairless.hairlesstoken>
There are some values Django cannot serialize into migration files.
For more, see https://docs.djangoproject.com/en/2.0/topics/migrations/#migration-serializing

@sdillinger
Copy link

same issue

@mcabrams
Copy link

ManyToMany relationships appear to be the issue here.

@alexei
Copy link
Owner

alexei commented May 2, 2019

I understand your pain. I built this in a couple of hours one day when I needed to rename a couple of models. Given this stuff is barely documented (I remember copying lots of code from the Django source code) I'm not sure I want to go through the same pain again and develop this further into a proper package. I sometimes feel like it's easier to just write the new models, copy the data, then delete the old models. Sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants