大家好,我有关于数据库迁移的问题.我试图从2.7切换到3.4,这是我在制作时获得的
adgc@mnl-adgc-pc1:~/Desktop/people$ python3 manage.py makemigrations Traceback (most recent call last): File "manage.py", line 10, inexecute_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" {} \;
在这里也可以看到它
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" {} \;
在这里也可以看到它