Why django migrations crashes using collections instead typing?
I have a class in models:
class UserFilters(typing.NamedTuple):
enabled_exchanges: typing.Optional[list[Exchange]] = None
enabled_coins: typing.Optional[list[Coin]] = None
enabled_fiats: typing.Optional[list[Fiat]] = None
enabled_paymethods: typing.Optional[list[Paymethod]] = None
consider_volumes: typing.Optional[bool] = None
consider_vendor_rating: typing.Optional[bool] = None
I run:
python3 manage.py makemigrations
Seems good
But when I run:
python3 manage.py migrate
Output is:
Traceback (most recent call last):
File "/Users/lifr0m/PycharmProjects/p2p/manage.py", line 22, in <module>
main()
File "/Users/lifr0m/PycharmProjects/p2p/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/core/management/base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/core/management/commands/makemigrations.py", line 88, in handle
loader = MigrationLoader(None, ignore_no_migrations=True)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/db/migrations/loader.py", line 53, in __init__
self.build_graph()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/db/migrations/loader.py", line 214, in build_graph
self.load_disk()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/db/migrations/loader.py", line 116, in load_disk
migration_module = import_module(migration_path)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/Users/lifr0m/PycharmProjects/p2p/authentication/migrations/0002_auto_20211213_1118.py", line 7, in <module>
class Migration(migrations.Migration):
File "/Users/lifr0m/PycharmProjects/p2p/authentication/migrations/0002_auto_20211213_1118.py", line 17, in Migration
field=models.JSONField(default=collections.UserFilters._asdict),
AttributeError: module 'collections' has no attribute 'UserFilters'
Why django imports my models from collections instead module.models? How can I fix that and is it a bug?
Versions:
Django 3.2.10
Python 3.10.0