gpt4 book ai didi

python - Django makemigrations错误

转载 作者:太空宇宙 更新时间:2023-11-04 08:52:05 24 4
gpt4 key购买 nike

大家好,我有一个关于数据库迁移的问题。我正在尝试从 2.7 切换到 3.4,这是我进行迁移时得到的结果

enter image description here

adgc@mnl-adgc-pc1:~/Desktop/people$ python3 manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/makemigrations.py", line 125, in handle
migration_name=self.migration_name,
File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/autodetector.py", line 43, in changes
changes = self._detect_changes(convert_apps, graph)
File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/autodetector.py", line 186, in _detect_changes
self.generate_altered_fields()
File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/autodetector.py", line 850, in generate_altered_fields
if old_field_dec != new_field_dec:
File "/usr/local/lib/python3.4/dist-packages/django/core/validators.py", line 55, in __eq__
self.regex.pattern == other.regex.pattern and
AttributeError: 'bytes' object has no attribute 'pattern'

最佳答案

python2 上的 Django 在代码中使用字节字符串创建迁移:

apps/post/migrations/0001_initial.py:                ('picture', models.ImageField(upload_to=b'images/posts/%Y_%m/%d', null=True, verbose_name='Picture', blank=True)),
apps/post/migrations/0001_initial.py: ('lang_code', models.ForeignKey(default=b'en', verbose_name='Language', to='account.Language')),

当我们在 python3 环境中运行它时,它崩溃了。

$ find apps -type f -exec sed -i "s/{b'/{'/g" {} \;        
$ find apps -type f -exec sed -i "s/(b'/('/g" {} \;
$ find apps -type f -exec sed -i "s/ b'/ '/g" {} \;
$ find apps -type f -exec sed -i "s/=b'/='/g" {} \;
$ find apps -type f -exec sed -i "s/\[b'/\['/g" {} \;

See it over here too

关于python - Django makemigrations错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34152138/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com