Opened 10 years ago
Closed 9 years ago
#24651 closed Bug (duplicate)
makemigrations: AttributeError: 'bytes' object has no attribute 'pattern' (Django 1.8/Python 3.4)
Reported by: | Luis Diego García | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 1.8 |
Severity: | Normal | Keywords: | |
Cc: | scailer@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I added two DateTimeFields to my model and wanted to run makemigrations.
Got this error:
Traceback (most recent call last): File "./manage.py", line 11, in <module> execute_from_command_line(sys.argv) File "/home/areca/venv/lf2/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line utility.execute() File "/home/areca/venv/lf2/lib/python3.4/site-packages/django/core/management/__init__.py", line 330, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/areca/venv/lf2/lib/python3.4/site-packages/django/core/management/base.py", line 390, in run_from_argv self.execute(*args, **cmd_options) File "/home/areca/venv/lf2/lib/python3.4/site-packages/django/core/management/base.py", line 441, in execute output = self.handle(*args, **options) File "/home/areca/venv/lf2/lib/python3.4/site-packages/django/core/management/commands/makemigrations.py", line 125, in handle migration_name=self.migration_name, File "/home/areca/venv/lf2/lib/python3.4/site-packages/django/db/migrations/autodetector.py", line 43, in changes changes = self._detect_changes(convert_apps, graph) File "/home/areca/venv/lf2/lib/python3.4/site-packages/django/db/migrations/autodetector.py", line 186, in _detect_changes self.generate_altered_fields() File "/home/areca/venv/lf2/lib/python3.4/site-packages/django/db/migrations/autodetector.py", line 850, in generate_altered_fields if old_field_dec != new_field_dec: File "/home/areca/venv/lf2/lib/python3.4/site-packages/django/core/validators.py", line 55, in __eq__ self.regex.pattern == other.regex.pattern and AttributeError: 'bytes' object has no attribute 'pattern'
Switched to a Python 2.7 environment and the error doesn't happen.
Change History (4)
comment:1 by , 10 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
comment:2 by , 9 years ago
Resolution: | needsinfo |
---|---|
Status: | closed → new |
I get same problem, when porting my code to python 3.
Django on python2 create migration with byte-strings in code:
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')),
And when we run it in python3 environ it crashes.
Works for me fix:
$ 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" {} \;
comment:3 by , 9 years ago
Cc: | added |
---|
comment:4 by , 9 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
The problem in the last comment is described in #24949.
Note:
See TracTickets
for help on using tickets.
It will be difficult to guess what's happening without more information. What are the compared validators? It might be that your migration files contain some unfortunate byte strings (b'...').