当前位置:  开发笔记 > 编程语言 > 正文

Django makemigrations错误

如何解决《Djangomakemigrations错误》经验,为你挑选了1个好方法。

大家好,我有关于数据库迁移的问题.我试图从2.7切换到3.4,这是我在制作时获得的

在此输入图像描述

adgc@mnl-adgc-pc1:~/Desktop/people$ python3 manage.py makemigrations
Traceback (most recent call last):
  File "manage.py", line 10, in 
    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'

Prashant Shu.. 5

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" {} \;

在这里也可以看到它



1> Prashant Shu..:

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" {} \;

在这里也可以看到它

推荐阅读
罗文彬2502852027
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有