Opened 5 years ago

Closed 5 years ago

#31045 closed Bug (invalid)

Squashing migrations returns "SyntaxError: Invalid token".

Reported by: Ben Mezger (seds) Owned by: nobody
Component: Migrations Version: 2.0
Severity: Normal Keywords: bug, migrations
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Ben Mezger (seds))

Seems that squashing my app migrations is returning the following error when running migrate. As far as I can see, 0060_auto_20190828_0652.update_store_locator_in_cart_page is an invalid identifier because it starts with a number. Perhaps checking running getattr before to avoid this issue.

I am not sure whether this is a Django issue or some other library conflict.

Traceback (most recent call last):
  File "manage.py", line 25, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/benmezger/.pyenv/versions/skyroam/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/Users/benmezger/.pyenv/versions/skyroam/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/benmezger/.pyenv/versions/skyroam/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/benmezger/.pyenv/versions/skyroam/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
    output = self.handle(*args, **options)
  File "/Users/benmezger/.pyenv/versions/skyroam/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 79, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/Users/benmezger/.pyenv/versions/skyroam/lib/python3.6/site-packages/django/db/migrations/executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/Users/benmezger/.pyenv/versions/skyroam/lib/python3.6/site-packages/django/db/migrations/loader.py", line 49, in __init__
    self.build_graph()
  File "/Users/benmezger/.pyenv/versions/skyroam/lib/python3.6/site-packages/django/db/migrations/loader.py", line 201, in build_graph
    self.load_disk()
  File "/Users/benmezger/.pyenv/versions/skyroam/lib/python3.6/site-packages/django/db/migrations/loader.py", line 110, in load_disk
    migration_module = import_module("%s.%s" % (module_name, migration_name))
  File "/Users/benmezger/.pyenv/versions/3.6.0/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 674, in exec_module
  File "<frozen importlib._bootstrap_external>", line 781, in get_code
  File "<frozen importlib._bootstrap_external>", line 741, in source_to_code
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "/Users/benmezger/workspace/ckl/skyroam_backend/store/migrations/0001_squashed_0071_product_custom_shipping_rate.py", line 1272
    code=store.migrations.0060_auto_20190828_0652.update_store_locator_in_cart_page,
                              ^
SyntaxError: invalid token

The generated migrations code: https://gist.github.com/benmezger/7e63f6a9e3b468b1838c67a7bd4a2bc4

Change History (2)

comment:1 by Ben Mezger (seds), 5 years ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 5 years ago

Component: Database layer (models, ORM)Migrations
Resolution: invalid
Status: newclosed
Summary: Squashing migrations returns "SyntaxError: Invalid token"Squashing migrations returns "SyntaxError: Invalid token".

I think you missed a comment at the begging of a squashed migration (see #22983):

# Functions from the following migrations need manual copying.
# Move them and any dependencies into this file, then update the
# RunPython operations to refer to the local versions:
# store.migrations.0060_auto_20190828_0652
Note: See TracTickets for help on using tickets.
Back to Top