Skip to content

name 'Serial' is not defined #865

@hoosnick

Description

@hoosnick

When creating a new migration, I think this bug(error) only occurs with ForeignKeys, details below:

my_app/tables.py
class Order(Table, tablename="orders"):
    user = ForeignKey(
        LazyTableReference(
            table_class_name="Users",
            module_path="users.tables"
        )
    )
    tariff = ForeignKey(
        LazyTableReference(
            table_class_name="Tariff",
            module_path="course.tables"
        )
    )
my_app/piccolo_migrations/my_app_2023_06_30t18_31_03_962663.py

Traceback
The command failed.
name 'Serial' is not defined
Traceback (most recent call last):
  File "path\to\project\env\Lib\site-packages\targ\__init__.py", line 448, in run      
    command.call_with(arg_class)
  File "path\to\project\env\Lib\site-packages\targ\__init__.py", line 229, in call_with
    asyncio.run(self.command(**cleaned_kwargs))
  File "path\to\programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "path\to\programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "path\to\programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "path\to\project\env\Lib\site-packages\piccolo\apps\migrations\commands\forwards.py", line 159, in forwards
    response = await run_forwards(
               ^^^^^^^^^^^^^^^^^^^
  File "path\to\project\env\Lib\site-packages\piccolo\apps\migrations\commands\forwards.py", line 120, in run_forwards
    response = await manager.run()
               ^^^^^^^^^^^^^^^^^^^
  File "path\to\project\env\Lib\site-packages\piccolo\apps\migrations\commands\forwards.py", line 97, in run
    return await self.run_migrations(app_config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "path\to\project\env\Lib\site-packages\piccolo\apps\migrations\commands\forwards.py", line 37, in run_migrations
    ] = self.get_migration_modules(app_config.migrations_folder_path)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "path\to\project\env\Lib\site-packages\piccolo\apps\migrations\commands\base.py", line 53, in get_migration_modules
    modules: t.List[MigrationModule] = [
                                       ^
  File "path\to\project\env\Lib\site-packages\piccolo\apps\migrations\commands\base.py", line 54, in <listcomp>
    t.cast(MigrationModule, importlib.import_module(name))
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "path\to\programs\Python\Python311\Lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "path\to\project\payment\piccolo_migrations\payment_2023_07_14t19_26_53_265153.py", line 20, in <module>
    class Tariff(Table, tablename="tariff", schema=None):
  File "path\to\project\payment\piccolo_migrations\payment_2023_07_14t19_26_53_265153.py", line 21, in Tariff
    id = Serial(
         ^^^^^^
NameError: name 'Serial' is not defined

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions